If compiled with GSL, random number generator types can be selected, as well as many more distribution types.
0 for the current time (seconds since 1970.00, see also time(2) )
-1 for the number of centiseconds since boot (see times(2) )
-2 for the current pid (see getpid(2) ).
-3 wishful thinking
the linux kernel will give an even more random seed
If GSL is implemented the seed value can be optionally followed by the random number generator type (default: mt19937). See xrandom(3) for more details.
#! /bin/csh -f # # n1: sample size # n2: number of times to do the experiment set n1=100 set n2=100 foreach i (‘nemoinp 1:$n2‘) set log=(‘xrandom -1 100 t | tail +2 | tabhist - tab=t |& grep ^Mean‘) echo $log[5] endThis script outputs n2 numbers, of which the mean should be 0 and the dispersion (now the error in the mean) 1/sqrt(n2), where 0 and 1 are the mean and dispersion of a random gaussian number from grandom(3NEMO) :
% grandom.csh | tabhist - 100 values read min and max value in column 1: [-0.335527 : 0.348629] Number of points : 100 Mean and dispersion : 0.0120416 0.102367 Skewness and kurtosis: -0.0528344 1.19066 Median : 0.000425562
xrandom can also be use to estimate the wall clock time of a complex pipe.
Here is an example using the centiseconds since boot timer from the seed=-1
mode:
t0=$(xrandom -1);mkplummer - 1000000 | snapsort - - r | hackdens - .; t1=$(xrandom -1); nemoinp "($t1-$t0)/100" 6.09where 6.09sec was measured on the fastest machine I had available at the time of this writing (Jansky, with nemobench5 ~ 1350). Turns out for this example about 90% of the CPU time is spent in hackdens(1NEMO) .
gaussian sigma gaussian_ratio_method sigma gaussian_tail a sigma exponential mu laplace a exppow a b cauchy a rayleigh sigma rayleigh_tail a sigma landau N/A levy c alpha levy_skey c alpha beta gamma a b flat a b lognormal zeta sigma chisq nu fdist nu1 nu2 tdist nu beta a b logistic a pareto a b weibull a b gumbel1 a b gumbel2 a bThe following functions are discrete random number distributions, and return integers:
poisson mu bernoulli p binomial p n negative_binomial p n pascal p k geometric p hypergeometric n1 n2 nt logarithmic sigma
echo $RANDOM echo $$ shuf -i 1-100 -n 5 awk -v n=5 -v seed="$RANDOM" ’BEGIN {srand(seed); for(i=0; i<n; ++i) printf("%.3f\n",rand())}’ tr -cd "[:digit:]" < /dev/urandom | head -c 6
Note that /dev/urandom is only available on Linux
26-Nov-96 V1.0 turned TESTBED into a TOOLBOX program PJT 13-apr-97 example 8-sep-01 V2.0 GSL optionally added PJT 9-oct-2012 V2.2 added m= PJT 21-aug-2022 V2.4 added exp= PJT 27-sep-2023 V2.5 less verbose and wall clock timing example added PJT