shithub: femtolisp

ref: 0b985dfc7f234dd1b61b817e510ddaeac38e0de7
dir: /random.c/

View raw version
#include "llt.h"
#include "mt19937-64.h"
#include "timefuncs.h"
#include "random.h"

static mt19937_64 ctx;

uint64_t
genrand_uint64(void)
{
	return genrand64_int64(&ctx);
}

uint32_t
genrand_uint32(void)
{
	return genrand64_int64(&ctx) >> 32;
}

int64_t
genrand_int63(void)
{
	return genrand64_int63(&ctx);
}

double
genrand_double(void)
{
	return genrand64_real1(&ctx);
}

void
randomize(void)
{
	unsigned long long tm = sec_realtime() * 1000.0;
	init_by_array64(&ctx, &tm, 1);
}