mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Fix endianness inconsistency with PcgRandom::bytes()
This commit is contained in:
parent
a423202756
commit
9fc2b93d9f
1 changed files with 10 additions and 25 deletions
|
@ -123,38 +123,23 @@ s32 PcgRandom::range(s32 min, s32 max)
|
|||
|
||||
void PcgRandom::bytes(void *out, size_t len)
|
||||
{
|
||||
u32 r;
|
||||
u8 *outb = (u8 *)out;
|
||||
int bytes_left = 0;
|
||||
u32 r;
|
||||
|
||||
size_t len_alignment = (uintptr_t)out % sizeof(u32);
|
||||
if (len_alignment) {
|
||||
len -= len_alignment;
|
||||
while (len--) {
|
||||
if (bytes_left == 0) {
|
||||
bytes_left = sizeof(u32);
|
||||
r = next();
|
||||
while (len_alignment--) {
|
||||
}
|
||||
|
||||
*outb = r & 0xFF;
|
||||
outb++;
|
||||
bytes_left--;
|
||||
r >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
size_t len_dwords = len / sizeof(u32);
|
||||
while (len_dwords--) {
|
||||
r = next();
|
||||
*(u32 *)outb = next();
|
||||
outb += sizeof(u32);
|
||||
}
|
||||
|
||||
size_t len_remaining = len % sizeof(u32);
|
||||
if (len_remaining) {
|
||||
r = next();
|
||||
while (len_remaining--) {
|
||||
*outb = r & 0xFF;
|
||||
outb++;
|
||||
r >>= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s32 PcgRandom::randNormalDist(s32 min, s32 max, int num_trials)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue