int init_xrandom(string init)int set_xrandom(int seed) double xrandom(double a, double b) double grandom(double m, double d) double frandom(double a, double b, real_proc func) double xrand(double a, double b)
set_xrandom initializes the random number generator with a supplied integer seed. If the seed is 0, the current UNIX time (see time(3) ) is used instead. It returns the seed used.
xrandom returns a uniformly distributed random number between a (inclusize) and b (exclusive).
grandom returns a gaussian distributed number with mean m and dispersion s.
frandom returns a a random number according to an arbitrary given probability function func(x), defined between x=a and x=b. This is implemented by defining a spline for the inverse normalized cumulative distribution function (F(x), with F(a)=0, F(b)=1), then pulling uniform random numbers between 0 and 1 and returning the corresponding random number between a and b.
Both grandom and frandom call xrandom, which in turn is defined in terms of either the portable random generator (to be installed through the include file options.h), or the unix random number generator random(3) .
xrand is a simple random number generator, with the same arguments as xrandom, but uses a much simpler algorithm, using the standard rand(3) . See also srand(3) when a seed is needed. It is not recommended to use xrand if xrandom is available.
We have special negative values:
0 unix number of seconds since 1970 -1 PID -2 number of centiseconds since boot -3 Ouput of unix "date +%Y%m%d%H%M%S" in case you need a more memorable seed
CFLAGS= first 4 random numbers [0,1) 0.968071 0.0667306 0.478281 0.909534 -DNUMREC 0.715119 0.0330211 0.874394 0.534194 -DRAND48 0.0416303 0.454492 0.834817 0.335986
~/src/kernel/misc xrandom.c frandom.c xrand.c
xx-xxx-86 created in the dark ages JEB 13-sep-90 portable random number generated installed PJT 17-sep-90 frandom written, for mass-spectra PJT 15-apr-91 added doc for set_xrandom PJT 7-jan-92 fixed seed bug in set_xrandom (from 13-sep-90) PJT 4-mar-94 documented xrand PJT 24-feb-00 documented special -1,-2 seeds PJT 8-sep-01 starting a GSL optional implementation, added init_xrandom PJT
Table of Contents