Documentation Index
Fetch the complete documentation index at: https://mintlify.com/akhildevelops/cudaz/llms.txt
Use this file to discover all available pages before exploring further.
Rng provides GPU-accelerated random number generation backed by the cuRAND library. It wraps a curandGenerator_t handle and a Device, exposing a simple interface for seeding the generator and producing arrays of uniform random f32 values entirely on the GPU. Generation is performed by curandGenerateUniform, which fills a device-side buffer without any host involvement in the sampling loop.
Import
Fields
| Field | Type | Description |
|---|---|---|
rng | curandGenerator_t | The underlying cuRAND generator handle |
device | Device | The device associated with this generator |
Functions
default
Rng on GPU 0 with seed 0. Uses the CURAND_RNG_PSEUDO_DEFAULT generator algorithm (a high-quality pseudo-random generator chosen by cuRAND). Internally calls Device.default() to initialize the device.
Returns: !@This() (an initialized Rng)
init
Rng on a specific device with a given seed. Pass null for seed to use the default seed of 0. Uses CURAND_RNG_PSEUDO_DEFAULT for the generator type, same as default.
An already-initialized
Device on which the RNG will operate. The generator uses the current context of this device.The 64-bit seed for the pseudo-random sequence. Pass
null to use 0. Different seeds produce independent random sequences; the same seed always produces the same sequence.!@This() (an initialized Rng)
genrandom
size uniform random f32 values in the half-open interval [0, 1) entirely on the GPU using curandGenerateUniform. Allocates a CudaSlice(f32) to hold the output; the caller owns the returned slice and must call slice.free() when done.
The initialized RNG to sample from. Each call advances the generator’s internal state.
Number of random
f32 values to generate. Must be even (cuRAND requirement for some generator types).!CudaSlice(f32)
Example
The Without this, compilation will fail with an undefined symbol error for
curand system library must be linked in your build.zig for Rng to work:curandCreateGenerator.