#include "sl.h"#include "cvalues.h"#include "mt19937-64.h"#include "timefuncs.h"#include "random.h" static mt19937_64 ctx; voidrandomize(void){ unsigned long long tm = sec_realtime() * 1000.0; init_by_array64(&ctx, &tm, 1);} BUILTIN("rand", rand){ argcount(nargs, 0);#ifdef BITS64 return fixnum(genrand64_int64(&ctx) >> 3);#else return fixnum(genrand64_int64(&ctx) >> (32+3));#endif} BUILTIN("rand-u32", rand_u32){ argcount(nargs, 0); return mk_u32(genrand64_int64(&ctx) >> 32);} BUILTIN("rand-u64", rand_u64){ argcount(nargs, 0); return mk_u64(genrand64_int64(&ctx));} BUILTIN("rand-f64", rand_f64){ argcount(nargs, 0); return mk_f64(genrand64_real1(&ctx));} BUILTIN("rand-f32", rand_f32){ argcount(nargs, 0); return mk_f32(genrand64_real1(&ctx));}
#include "sl.h"
#include "cvalues.h"
#include "mt19937-64.h"
#include "timefuncs.h"
#include "random.h"
static mt19937_64 ctx;
void
randomize(void)
{
unsigned long long tm = sec_realtime() * 1000.0;
init_by_array64(&ctx, &tm, 1);
}
BUILTIN("rand", rand)
{
argcount(nargs, 0);
#ifdef BITS64
return fixnum(genrand64_int64(&ctx) >> 3);
#else
return fixnum(genrand64_int64(&ctx) >> (32+3));
#endif
}
BUILTIN("rand-u32", rand_u32)
{
argcount(nargs, 0);
return mk_u32(genrand64_int64(&ctx) >> 32);
}
BUILTIN("rand-u64", rand_u64)
{
argcount(nargs, 0);
return mk_u64(genrand64_int64(&ctx));
}
BUILTIN("rand-f64", rand_f64)
{
argcount(nargs, 0);
return mk_f64(genrand64_real1(&ctx));
}
BUILTIN("rand-f32", rand_f32)
{
argcount(nargs, 0);
return mk_f32(genrand64_real1(&ctx));
}