Last version:
FLUKA 2023.3.3, January 31st 2024
(last respin 2023.3.3)
flair-2.3-0d 13-Sep-2023

News:

-- Fluka Release
( 31.01.2024 )

FLUKA 2023.3.3 has been released.
Next FLUKA Course
The 23rd FLUKA course
will be held at the Lanzhou University, China, on June 1-8, 2024


font_small font_med font_big print_ascii

previous FAQback to FAQ listnext FAQ

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 FLNRRN(RGAUSS) which returns a normal gaussian number RGAUSS

CALL FLNRR2(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

Q:

When programming code in the user routines, is there a recommended way of giving numerical constants?

A:

When the user has to insert a numerical constant in the user code, he must always give it explicitly either in INTEGER, if this is the case, or in DOUBLE PRECISION. This is fundamental especially when geometrical accuracy is involved (for example when using a routine like lattic.f). Therefore one should never write something like '4.2' but instead '4.2D+00'. Most compilers treat the two cases in different ways. In this respect, whenever possible, the user should make use of the constants defined as PARAMETER in the (DBLPRC) include file.

It is also important to know that all numerical values passed on the code by data cards are automatically interpreted in DOUBLE PRECISION.



Last updated: 26th of April, 2016

© FLUKA Team 2000–2024

Informativa cookies