Go to the documentation of this file.
13 static uint32_t x = 123456789;
14 static uint32_t y = 362436069;
15 static uint32_t z = 521288629;
16 static uint32_t w = 88675123;
18 static int _rand(
void) {
23 w = w ^ (w >> 19) ^ t ^ (t >> 8);
25 return (w & RAND_MAX);
28 void _srand(
unsigned int seed) {
29 x = 123456789 ^ (seed << 16) ^ (seed >> 16);
35 KRK_Function(random) {
36 FUNCTION_TAKES_NONE();
38 double r = (double)_rand() / (double)(RAND_MAX);
40 return FLOATING_VAL(r);
44 FUNCTION_TAKES_AT_MOST(1);
48 CHECK_ARG(0,
int,krk_integer_type,_seed);
52 gettimeofday(&tv,NULL);
54 seed = tv.tv_sec ^ tv.tv_usec;
62 KRK_DOC(module,
"Functions for generating pseudo-random numbers.");
64 BIND_FUNC(module, random);
65 BIND_FUNC(module, seed);
67 FUNC_NAME(krk,seed)(0,NULL,0);
Utilities for creating native bindings.
#define KRK_DOC(thing, text)
Attach documentation to a thing of various types.
Core API for the bytecode virtual machine.