--- Functions, subroutines and Fortran programming


Q:
What is the correct way of generating random numbers to be used in a user-specific source routine?

A:
The FLUKA random number generator can be invoked using the FLRNDM(XDUMMY)
function. It returns a 64-bit pseudo random number in the interval
[0.D+00,1.D+00), 1 being not included. 
See also next question about the argument of FLRNDM argument.
FLRNDM gurarantees an extremely low
peridiocity (of the order of 10*44). Any other function, for instance the
intrinsic random generator of fortran or other functions belonging to 
external libraries, must be absolutely avoided, since they follow a
different seed history and break any possibility of a correct use of 
the last seed in progressive runs. 




Q:
When using the FLRNDM random number generator function in user routines, what argument must be used?

A:
In general, any name is ok, provided it begins by A-H, O-Z. If possible,
it is suggested to use the name of a variable which has been recently
modified, otherwise it doesn't matter. The reason is that in the far past
some compiler tried to be "clever" by extracting the function call when it
was present inside a DO loop (in principle, a function with constant
argument is supposed to give a constant result - but not a random number
generator!). Therefore, it is safer to fool the compiler by letting it
believe that the argument has changed, but fortunately such dumb compilers
seem to have disappeared.
With most compilers accepting f90 extensions, it is now allowed also to
write FLRNDM( ) without any argument.




Q:
Are there in FLUKA other utilities for generation and manipulation of random numbers?

A:
Yes. In particular the use of the following subroutines is recommended
whenever useful:

 CALL FLNRNN(RGAUSS) which returns a normal gaussian number RGAUSS

 CALL FLNRN2(RGAUS1,RGAUS2) which returns two independent normal gaussian
                            numbers RGAUS1 and RGAUS2

 CALL SFECFE(SINT,COST) which returns a pair of random numbers SINT and
                        COST such that SINT**2+COST**2 = 1.D+00 and
                        therefore can be interpreted as Sin() and Cos()
			of the same random angle, uniformly distributed 
                        in the range 0-2 Pi.

 CALL RACO(TXX,TYY,TZZ) which returns 3 random numbers TXX, TYY, TZZ such
                        that TXX**2 + TYY**2 + TZZ**2 = 1.D+00 and
                        therefore can be interpreted as the cosine
                        directors of a random (isotropically distributed)
                        direction in 3-D cartesian space, i.e. reconducible
                        to a pair of angles: a uniformly distributed
                        azimuthal angle phi in the range 0-2Pi and a polar 
                        angle theta uniformly distributed in cos(theta) 
                        in the range -1,+1
 
top / back
sponsored by: INFN and CERN updated: