* Switch random back to 32 bits. It's enough (tm).

This commit is contained in:
Sam Hocevar 2006-12-15 14:57:59 +00:00 committed by sam
parent f8fcc918b8
commit c73bf4e00f
2 changed files with 6 additions and 9 deletions

View File

@ -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)));
}

View File

@ -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);