curand.cu
Documentation for the core CUDA kernels used in the simulation.
Functions
Functions
-
__device__ void init_monty_rand(int seed)
Initializes the cuRAND random number generator state for each GPU thread.
- Parameters:
seed – The value used to randomize the generator’s starting state.
- Returns:
void
-
__device__ void generate_random_direction(double *x, double *y, double *z, curandState *localState)
Generates a random 3D unit vector uniformly distributed on the sphere.
Uses Marsaglia’s method (also attributed to Knop; CACM 13 (1970), 326) to generate an isotropic direction by sampling points uniformly inside the unit disk and mapping them to the surface of the unit sphere.
See also
[Algorithm 381: random vectors uniform in solid angle] (https://dl.acm.org/doi/10.1145/362349.362377)
- Parameters:
x – Pointer to the x-component of the resulting unit vector.
y – Pointer to the y-component of the resulting unit vector.
z – Pointer to the z-component of the resulting unit vector.
localState – Pointer to the thread-local cuRAND state.
-
__device__ double chi_square(int df, curandState *localState)
Samples a Chi-square distributed random variable for a given degree of freedom. Uses the transformation property where a Chi-square distribution with \(k\) degrees of freedom is equivalent to a Gamma distribution scaled by 2: \(\chi^2(k) \sim 2\Gamma(k/2, 1)\). χ
See also
- Parameters:
df – Degrees of freedom ( \(k\)).
localState – Pointer to the thread-local cuRAND state.
- Returns:
A random value sampled from the \(\chi^2\) distribution.
-
__device__ double legacy_standard_exponential(curandState *localState)
Samples a random variable from the standard exponential distribution ( \(\lambda = 1\)). Implements the Inverse Transform Sampling method by transforming a uniform \((0,1]\) random variable into an exponential distribution.
See also
- Parameters:
localState – Pointer to the thread-local cuRAND state.
- Returns:
A random value sampled from the exponential distribution.
-
__device__ void legacy_gauss(double *out1, double *out2, curandState *localState)
Generates two independent standard normal variables ( \(\mu=0, \sigma=1\)) using the Marsaglia polar method. This is a rejection-based variant of the Box-Muller transform that avoids trigonometric functions by sampling coordinates within a unit circle.
See also
- Parameters:
out1, out2 – Pointers to store the two independent Gaussian results.
localState – Pointer to the thread-local cuRAND state.
-
__device__ double legacy_standard_gamma(double shape, curandState *localState)
Samples a standard Gamma distribution ( \(\Gamma(\alpha, 1)\)) using Marsaglia-Tsang (for \( \alpha \geq 1 \)) and an acceptance–rejection transformation to reduce the problem to the shape ≥ 1 case (for \( \alpha < 1 \)).
- Parameters:
shape – Shape parameter ( \(\alpha\)) of the distribution.
localState – Pointer to the thread-local cuRAND state.
- Returns:
A random value sampled from the Gamma distribution.