next up previous index
Next: CONS001 Introduction to Up: GEANT Previous: BASE410 Utility Routines

BASE420 The random number generator

Routine ID: BASE420
Author(s): Submitted: 27.07.93
Origin: R.Brun, F.CarminatiRevised: 14.12.93

CALL GRNDM (VEC*,LEN)

VEC
( REAL) vector containing the generated random number;
LEN
( INTEGER) number of random numbers to generate.

GRNDM generates a sequence of uniformly distributed random numbers in the interval (0,1). The numbers are returned in a vector. The code is a copy of the CERN Program Library routine RANECU [,] (entry V114).

Several independent sequences can be defined and used. Each sequence must be initialised by the user, otherwise the result is unpredictable. Two integer seeds are used to initialise a sequence. Not all pairs of integers define a good random sequence or one which is independent from others. Sections of the same random sequence can be defined as independent sequences. The period of the generator is 260≈1018 . A generation has been performed in order to provide the seeds to start any of the generated sections. There are 215 possible seed pairs and they are all 109 numbers apart. Thus a sequence started from one of the seed pairs, after 109

numbers will start generating the next one.

CALL GRNDMQ (ISEED1,ISEED2,ISEQ,CHOPT)

ISEED1
( INTEGER) first seed of the sequence;
ISEED2
( INTEGER) second seed of the sequence;
ISEQ
( INTEGER) number of the independent sequence of random numbers referred to by this call. If ISEQ 0, then the last valid sequence used will be addressed either for a save or a store. In case the option 'G' is specified, on output the variable will contain the sequence actually used;
CHOPT
( CHARACTER*(*)) the action to be taken:
' '
if 1 ISEQ 215, sequence number ISEQ will be initialised with the seeds of the pre-computed independent sequence ISEQ.

If ISEQ 0 or ISEQ>215, sequence number 1 will be initialised with the default seeds. ISEED1 and ISEED2 are ignored;

'G'
get the present status of the generator: the two integer seeds ISEED1 and ISEED2 will be returned for sequence ISEQ;
'S'
set the status of the generator. The two integer seeds ISEED1 and ISEED2 will be used to restart the generator for sequence ISEQ.
'SH'
the same action as for 'S' and store the two integer seeds ISEED1 and ISEED2 in the event header bank.
'Q'
Get the pre-generated seeds for ISEQ (1 ISEQ 215). There are 215 pre-generated sequences each one will generate 109 numbers before reproducing the following one.

Initialises the random number generator.

GARNDMVALUE = GARNDM(DUMMY)

DUMMY
( REAL) dummy parameter, ignored;

Returns a random number r distributed as e-x . r = -ln(η)

where η is a random number extracted by GRNDM.

CALL GPOISS (AMVEC,NPVEC*,LEN)

AMVEC
( REAL) array of length LEN containing the average values of the Poisson distributions requested;
NPVEC
( INTEGER) array of length LEN containing the random numbers: NPVEC(I) is a random number with a Poisson distribution of average AMVEC(I);
LEN
( INTEGER) number of random numbers requested.

This routine extracts integer random numbers according to the Poisson distribution. Given a Poisson distribution of average λ≤16

and r uniformly distributed between 0 and 1, the method used is the following:

  1. let P = exp(-λ) , N=0 and S=P;
  2. if r≤S accept N;
  3. let N=N+1, P=P λ/N , S=S+P and go back to 2;

If λ> 16 , a gaussian distribution with average λ and σ= λ is generated.

F.Bruyant CONS001



next up previous index
Next: CONS001 Introduction to Up: GEANT Previous: BASE410 Utility Routines


Janne Saarela
Mon Apr 3 12:46:29 METDST 1995