Table of Contents

If compiled with GSL, random number generator types can be selected, as well as many more distribution types.

**seed=**- Initial
seed. Values 0 and below are special:
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. **n=**- Number of random numbers to draw [Default: 0].
**m=**- Number of times to repeat the experiment.
If more than 1, tabulating is turned off, and reporting is now doine at
the end of all tests, and the statistics of the mean’s from each
**n**sample is shown. [Default: 1]. **gauss=**- Return gaussian numbers instead of uniform? [Default: f]
**exp=**- Return exponential random numbers instead. Setting this
will override the
**gauss=**parameter. [Default: f] **report=**- Report mean/dispersion/skewness/kurtosis? [Default: f]
**tab=t|f**- Tabulate all random numbers [t]
**offset=**- Offset of distribution from 0. Default: 0.0
**gsl=**- Name of the random number distribution
requested. They follow the name convention of the same-name functions
*gsl_random_xxx*in the*gsl(3)*library. Only available if compiled with GSL. No default. **pars=**- Parameters belonging to the selected
**gsl**name. They need to match exactly (0, 1, 2 or 3 currently). No default. **seed57=**- This quaint option will activate
von Hoerner’s 1957 algorithm of drawing random numbers. It needs a seed between
0.57 and 0.91. See also
*mkvh60(1NEMO)*. Default: not used.

#! /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

% 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-96V1.0 turned TESTBED into a TOOLBOX programPJT 13-apr-97example 8-sep-01V2.0 GSL optionally addedPJT 9-oct-2012V2.2 added m=PJT 21-aug-2022V2.4 added exp=PJT 27-sep-2023V2.5 less verbose and wall clock timing example addedPJT