ref: 108a9de63855e85b23b98edcffa095ffed9eb9f8
dir: /src/random.c/
#include "flisp.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) { USED(args); USED(nargs); #ifdef BITS64 return fixnum(genrand64_int64(&ctx) >> 3); #else return fixnum(genrand64_int64(&ctx) >> (32+3)); #endif } BUILTIN("rand-uint32", rand_uint32) { USED(args); USED(nargs); return mk_uint32(genrand64_int64(&ctx) >> 32); } BUILTIN("rand-uint64", rand_uint64) { USED(args); USED(nargs); return mk_uint64(genrand64_int64(&ctx)); } BUILTIN("rand-double", rand_double) { USED(args); USED(nargs); return mk_double(genrand64_real1(&ctx)); } BUILTIN("rand-float", rand_float) { USED(args); USED(nargs); return mk_float(genrand64_real1(&ctx)); }