Files
asteroids/rng.c

33 lines
445 B
C

#include "rng.h"
#include <assert.h>
#include <sys/time.h>
static uint32_t state;
void rng_init()
{
struct timeval tv;
const int res = gettimeofday(&tv, nullptr);
assert(res == 0);
state = tv.tv_usec;
}
uint32_t rng_uint32()
{
state ^= state << 13;
state ^= state >> 17;
state ^= state << 5;
return state;
}
float rng_canon()
{
return (float)rng_uint32() / UINT32_MAX;
}
float rng_plusminus()
{
return 2.0 * rng_canon() - 1.0;
}