HTML automatically generated with rman
Table of Contents
xrandom - Return seed for random numbers and optionally random numbers
xrandom [parameter=value]
xrandom returns a seed that
can be used to random number generators, and optionally random numbers
drawn from a uniform or gaussian (normal) distribution. Uniform numbers
are between 0 and 1, gaussian numbers have a mean of 0 and a dispersion
of 1.
If compiled with GSL, random number generator types can be selected,
as well as many more distribution types.
The following parameters
are recognized in any order if the keyword is also given:
- seed=
- Initial
seed. Use 0 for the current time (seconds since 1970.00, see also time(2)
)
-1 for the number of centiseconds since boot (see times(2)
) and 2 for the
current pid (see getpid(2)
). 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]
- 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.
Here is an example script, grandom.csh, to test
if the error in the mean scales as 1/sqrt(N):
#! /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]
end
This 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
If the GNU Scientific Library (GSL) has been enabled during installation,
the gsl= and pars keyword will appear in the keyword list of xrandom. The
following random number distribution names are implemented, and the names
of their parameters. Note that the number of parameters, as given in pars=
has to match exactly, there are no defaults.
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 b
The 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
Random numbers can be seeded using the seed= keyword. There are also
Unix ways to do this. Here are a few (using bash notation):
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())}’
Peter Teuben
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
Table of Contents