PLUTO
4.4-patch2
|
Miscellaneous random number generator functions. More...
#include "pluto.h"
Functions | |
double | RandomNumber (double rmin, double rmax) |
void | RandomSeed (long int seed, long int offset) |
double | GaussianRandomNumber (double mu, double sigma) |
double | PowerLawRandomNumber (double xmin, double xmax, double n) |
double | NR_ran2 (long int *idum) |
Some useful links:
double GaussianRandomNumber | ( | double | mu, |
double | sigma | ||
) |
Generate random deviates with a normal Gaussian distribution with mean mu and standard deviation sigma. (Adapted from Numerical Recipe, see "Normal (Gaussian) Deviates in Chap. 7)
double NR_ran2 | ( | long int * | idum | ) |
Long period (> 2 x 10^{18}) random number generator of L'Ecuyer with Bays-Durham shuffle and added safeguards. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of the endpoint values). Call with idum a negative integer to initialize; thereafter, do not alter idum between successive deviates in a sequence. RNMX should approximate the largest floating value that is less than 1.
Example:
Reference:
double PowerLawRandomNumber | ( | double | xmin, |
double | xmax, | ||
double | n | ||
) |
Generate random deviates with a power-law distribution. Here xmin and xmax are the distribution range and n is the power-law index (n != -1)
double RandomNumber | ( | double | rmin, |
double | rmax | ||
) |
Generate and return a random number between [rmin, rmax] using the PLUTO random number generator.
Sequence must already have been seeded using RandomSeed() function (see below).
Generate a random number between a and b:
In parallel, you must ensure different sequences are generated on different processors.
void RandomSeed | ( | long int | seed, |
long int | offset | ||
) |
Seed the random number generator. Important: the seed must be called only once per sequence.
[in] | seed | long integer used to seed the random number generator |
[in] | offset | long integer specifying the offset where to start the sequence (only when offset > 0). Otherwise (offset <= 0) no offset is used. |
In parallel, each processor uses a different sequence obtained by offsetting the initial one by offset*prank elements. For example, if offset = 8 and 2 processors are used, a total of 16 numbers (8 per processor) are generated. Each processor starts at a different point in the sequence:
r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r16 <---------- rank 0 ----------> <-------------- rank 1 -------------->
Example: