Skip to content

Random Number Generators ​

Module-level rand, randn, and randexp are documented under Initialization. This page covers the cuPyNumeric RNG stack: BitGenerators, Generator, and default_rng.

Random draws use cuRAND with the XORWOW random number generator by default. We support Float32 and Float64 uniforms, normals, and exponentials (randexp), ComplexF32 / ComplexF64 uniforms and normals (independent real/imag parts, without randexp), Bool coin flips, and signed Int16 / Int32 / Int64. There is no native Bool or complex distribution, so rand(Bool, …) draws Int16 values in {0,1} and compares them to zero. Complex arrays combine two real arrays as re + i*imag.

Random.seed! is not implemented. Use default_rng with an explicit seed (or a specific BitGenerator) when you need a private stream. Module-level rand / randn / randexp always use a process-global XORWOW generator.

BitGenerators ​

cuNumeric.BitGenerator Type
julia
BitGenerator

Abstract supertype for cuRAND engines used by Generator. Concrete types are XORWOW (default), MRG32k3a, and PHILOX4_32_10.

source
cuNumeric.XORWOW Type
julia
XORWOW(seed=nothing; flags=0)

Default cuRAND BitGenerator (xorwow). seed=nothing draws from time_ns().

source
cuNumeric.MRG32k3a Type
julia
MRG32k3a(seed=nothing; flags=0)

cuRAND MRG32k3a BitGenerator.

source
cuNumeric.PHILOX4_32_10 Type
julia
PHILOX4_32_10(seed=nothing; flags=0)

cuRAND Philox4_32_10 BitGenerator.

source

Generator ​

cuNumeric.Generator Type
julia
Generator(bit_generator)

cuPyNumeric-style RNG wrapping a BitGenerator. Module-level rand, randn, randexp use a process-global XORWOW generator; pass a different engine to default_rng for Philox or MRG32k3a.

source
cuNumeric.default_rng Function
julia
default_rng()
default_rng(seed)
default_rng(::Type{<:BitGenerator}, seed=nothing; flags=0)
default_rng(bit_generator)
default_rng(generator)

Return a Generator. The no-argument and integer-seed methods use XORWOW. This does not replace the process-global generator used by module-level rand / randn.

julia
g = cuNumeric.default_rng(cuNumeric.PHILOX4_32_10, 1234)
cuNumeric.random(g, Float32, (8, 8))
source
julia
using cuNumeric
import Random

g = cuNumeric.default_rng()                          # XORWOW, fresh seed
g = cuNumeric.default_rng(1234)                      # XORWOW, fixed seed
g = cuNumeric.default_rng(cuNumeric.PHILOX4_32_10, 1)
A = cuNumeric.random(g, Float32, (8, 8))             # U[0, 1)
Random.randn!(g, A)                               # N(0, 1)
Random.randexp!(g, A; scale=1)                    # Exp(scale)