|
SDDS ToolKit Programs and Libraries for C and Python
|
Random number generation functions providing various distributions (uniform, Gaussian) and related utilities (seeding, ordering, etc.).
Definition in file drand.c.
#include "mdb.h"#include <time.h>#include <stdlib.h>#include "f2c.h"Go to the source code of this file.
Functions | |
| double | dlaran_ (integer *seed) |
| double | dlaran_oag (integer *seed, long increment) |
| float | drand (long dummy) |
| Generate a uniform random float in [0,1]. | |
| double | rdrand (double lo, double hi) |
| Generate a uniform random double in [lo, hi]. | |
| void | tseed () |
| void | r_theta_rand (double *r, double *theta, double r_min, double r_max) |
| Generate a random point (r, θ) within an annulus defined by [r_min, r_max]. | |
| short | inhibitRandomSeedPermutation (short state) |
| Enable or disable permutation of seed bits for random number generators. | |
| long | permuteSeedBitOrder (long input0) |
| Permute the bit order of a seed value to improve randomness. | |
| double | random_1 (long iseed) |
| Generate a uniform random double in [0,1] using a custom seed initialization. | |
| double | random_2 (long iseed) |
| Similar to random_1(), provides a separate random sequence with its own seed handling. | |
| double | random_3 (long iseed) |
| Similar to random_2(), provides another independent random sequence. | |
| double | random_4 (long iseed) |
| Similar to random_3(), provides another independent random sequence. | |
| double | random_5 (long iseed) |
| Similar to random_4(), provides another independent random sequence. | |
| double | random_6 (long iseed) |
| Similar to random_5(), provides another independent random sequence. | |
| double | gauss_rn (long iseed, double(*urandom)(long iseed1)) |
| Generate a Gaussian-distributed random number with mean 0 and sigma 1. | |
| double | gauss_rn_lim (double mean, double sigma, double limit_in_sigmas, double(*urandom)(long iseed)) |
| Generate a Gaussian-distributed random number with specified mean, sigma, and optional cutoff. | |
| long | convertSequenceToGaussianDistribution (double *data, long points, double limit) |
| Convert a sequence of uniformly distributed [0,1] values into a Gaussian-distributed sequence. | |
| int | randomizeOrderCmp (const void *p1, const void *p2) |
| long | randomizeOrder (char *ptr, long size, long length, long iseed, double(*urandom)(long iseed1)) |
| Randomize the order of an array of elements. | |
| double | random_oag (long iseed, long increment) |
| Generate a uniform random double in [0,1] using a seed and increment, optimized for certain applications. | |
| double | gauss_rn_oag (long iseed, long increment, double(*urandom)(long iseed1, long increment)) |
Generate a Gaussian-distributed random number using the random_oag approach. | |
| double | gauss_rn_lim_oag (double mean, double sigma, double limit_in_sigmas, long increment, double(*urandom)(long iseed, long increment)) |
Generate a Gaussian-distributed random number with mean, sigma, and optional cutoff using oag RNG. | |
| long convertSequenceToGaussianDistribution | ( | double * | data, |
| long | points, | ||
| double | limit ) |
Convert a sequence of uniformly distributed [0,1] values into a Gaussian-distributed sequence.
Uses the inverse error function (erf) to transform uniform data into Gaussian distributed data. Values that exceed the given limit are discarded.
| [in,out] | data | Array of input values in [0,1] to be converted. |
| [in] | points | Number of values in the array. |
| [in] | limit | Upper cutoff in standard deviations (if <= 0, no cutoff). |
Definition at line 406 of file drand.c.
|
extern |
Definition at line 33 of file dlaran.c.
|
extern |
Definition at line 125 of file dlaran.c.
| float drand | ( | long | dummy | ) |
| double gauss_rn | ( | long | iseed, |
| double(* | urandom )(long iseed1) ) |
Generate a Gaussian-distributed random number with mean 0 and sigma 1.
Uses the given uniform random generator urandom to produce Gaussian deviates via the Box–Muller transform.
| [in] | iseed | If negative, re-initializes the uniform RNG. |
| [in] | urandom | Pointer to a uniform random number generator function. |
Definition at line 341 of file drand.c.
| double gauss_rn_lim | ( | double | mean, |
| double | sigma, | ||
| double | limit_in_sigmas, | ||
| double(* | urandom )(long iseed) ) |
Generate a Gaussian-distributed random number with specified mean, sigma, and optional cutoff.
If limit_in_sigmas > 0, values are regenerated until the deviate falls within ±limit_in_sigmas*sigma.
| [in] | mean | Mean of the Gaussian distribution. |
| [in] | sigma | Standard deviation of the Gaussian distribution. |
| [in] | limit_in_sigmas | Cutoff in multiples of sigma (if <= 0, no cutoff). |
| [in] | urandom | Pointer to a uniform random number generator function. |
Definition at line 378 of file drand.c.
| double gauss_rn_lim_oag | ( | double | mean, |
| double | sigma, | ||
| double | limit_in_sigmas, | ||
| long | increment, | ||
| double(* | urandom )(long iseed, long increment) ) |
Generate a Gaussian-distributed random number with mean, sigma, and optional cutoff using oag RNG.
If limit_in_sigmas > 0, values are regenerated until they fall within the cutoff range.
| [in] | mean | Mean of the Gaussian distribution. |
| [in] | sigma | Standard deviation of the Gaussian distribution. |
| [in] | limit_in_sigmas | Cutoff in multiples of sigma (if <= 0, no cutoff). |
| [in] | increment | Increment step for random number generation. |
| [in] | urandom | Pointer to an oag-style uniform random number generator function. |
Definition at line 559 of file drand.c.
| double gauss_rn_oag | ( | long | iseed, |
| long | increment, | ||
| double(* | urandom )(long iseed1, long increment) ) |
Generate a Gaussian-distributed random number using the random_oag approach.
Uses a modified Box–Muller method to generate Gaussian deviates from the urandom function provided.
| [in] | iseed | Seed for initialization if negative. |
| [in] | increment | Increment step for random number generation. |
| [in] | urandom | Pointer to an oag-style uniform random number generator function. |
Definition at line 534 of file drand.c.
| short inhibitRandomSeedPermutation | ( | short | state | ) |
Enable or disable permutation of seed bits for random number generators.
If state >= 0, sets the inhibitPermute flag. Otherwise, returns the current state without changing it.
| [in] | state | New state for inhibition (0 = no inhibition, 1 = inhibited). |
Definition at line 93 of file drand.c.
| long permuteSeedBitOrder | ( | long | input0 | ) |
Permute the bit order of a seed value to improve randomness.
Applies a permutation of the seed bits to avoid predictable patterns. If inhibition is enabled, returns the original input.
| [in] | input0 | The seed value to permute. |
Definition at line 109 of file drand.c.
| void r_theta_rand | ( | double * | r, |
| double * | theta, | ||
| double | r_min, | ||
| double | r_max ) |
Generate a random point (r, θ) within an annulus defined by [r_min, r_max].
The angle θ is chosen uniformly in [0, 2π), and r is chosen so that the area distribution is uniform.
| [out] | r | Pointer to store the generated radius. |
| [out] | theta | Pointer to store the generated angle in radians. |
| [in] | r_min | The inner radius of the annulus. |
| [in] | r_max | The outer radius of the annulus. |
Definition at line 75 of file drand.c.
| double random_1 | ( | long | iseed | ) |
Generate a uniform random double in [0,1] using a custom seed initialization.
Initializes the random number generator if needed, and then produces a double in [0,1]. Negative iseed values are used to re-initialize the sequence.
| [in] | iseed | Seed for initialization if negative, otherwise ignored after first call. |
Definition at line 175 of file drand.c.
| double random_2 | ( | long | iseed | ) |
Similar to random_1(), provides a separate random sequence with its own seed handling.
| [in] | iseed | Seed for initialization if negative. |
Definition at line 207 of file drand.c.
| double random_3 | ( | long | iseed | ) |
Similar to random_2(), provides another independent random sequence.
| [in] | iseed | Seed for initialization if negative. |
Definition at line 233 of file drand.c.
| double random_4 | ( | long | iseed | ) |
Similar to random_3(), provides another independent random sequence.
| [in] | iseed | Seed for initialization if negative. |
Definition at line 259 of file drand.c.
| double random_5 | ( | long | iseed | ) |
Similar to random_4(), provides another independent random sequence.
| [in] | iseed | Seed for initialization if negative. |
Definition at line 285 of file drand.c.
| double random_6 | ( | long | iseed | ) |
Similar to random_5(), provides another independent random sequence.
| [in] | iseed | Seed for initialization if negative. |
Definition at line 311 of file drand.c.
| double random_oag | ( | long | iseed, |
| long | increment ) |
Generate a uniform random double in [0,1] using a seed and increment, optimized for certain applications.
Uses a custom random number generator implemented in Fortran (dlaran_oag).
| [in] | iseed | Seed for initialization if negative. |
| [in] | increment | Increment to apply for each call. |
Definition at line 503 of file drand.c.
| long randomizeOrder | ( | char * | ptr, |
| long | size, | ||
| long | length, | ||
| long | iseed, | ||
| double(* | urandom )(long iseed1) ) |
Randomize the order of an array of elements.
Shuffles the elements of an array using a provided uniform random generator.
| [in,out] | ptr | Pointer to the array to randomize. |
| [in] | size | Size of each element in bytes. |
| [in] | length | Number of elements in the array. |
| [in] | iseed | Seed for initialization if negative. |
| [in] | urandom | Pointer to a uniform random number generator function. |
Definition at line 465 of file drand.c.
| int randomizeOrderCmp | ( | const void * | p1, |
| const void * | p2 ) |
Definition at line 441 of file drand.c.
| double rdrand | ( | double | lo, |
| double | hi ) |