* Switch random back to 32 bits. It's enough (tm).
This commit is contained in:
parent
f8fcc918b8
commit
c73bf4e00f
11
src/random.c
11
src/random.c
@ -27,20 +27,17 @@
|
||||
|
||||
#include "random.h"
|
||||
|
||||
void zzuf_srand(uint64_t seed)
|
||||
void zzuf_srand(uint32_t seed)
|
||||
{
|
||||
uint32_t a = seed & 0xffffffff;
|
||||
uint32_t b = seed >> 32;
|
||||
|
||||
srand((a ^ 0x12345678) * (b ^ 0x87654321));
|
||||
srand(seed ^ 0x12345678);
|
||||
}
|
||||
|
||||
uint64_t zzuf_rand(uint64_t max)
|
||||
uint32_t zzuf_rand(uint32_t max)
|
||||
{
|
||||
if(max <= RAND_MAX)
|
||||
return rand() % max;
|
||||
|
||||
/* Could be better, but do we care? */
|
||||
return (uint64_t)((max * 1.0) * (rand() / (RAND_MAX + 1.0)));
|
||||
return (uint32_t)((max * 1.0) * (rand() / (RAND_MAX + 1.0)));
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,6 @@
|
||||
* random.h: pseudorandom number generator
|
||||
*/
|
||||
|
||||
void zzuf_srand(uint64_t);
|
||||
uint64_t zzuf_rand(uint64_t);
|
||||
void zzuf_srand(uint32_t);
|
||||
uint32_t zzuf_rand(uint32_t);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user