Mojo module
random
Random number generation for GPU kernels.
This module implements a high-performance random number generator using the Philox algorithm, which is designed for parallel and GPU computing. The Philox algorithm is a counter-based random number generator that provides high-quality random numbers with excellent statistical properties.
The main class is Random which generates both uniform random numbers and raw 32-bit integers. It supports:
- Seeding for reproducible sequences
- Multiple independent subsequences
- Configurable number of rounds for quality vs performance tradeoff
- Vectorized operations for efficiency
Example:
from gpu.random import Random
rng = Random(seed=42)
uniform_values = rng.step_uniform() # Returns 4 random floats in [0,1)
raw_values = rng.step() # Returns 4 raw 32-bit integers
from gpu.random import Random
rng = Random(seed=42)
uniform_values = rng.step_uniform() # Returns 4 random floats in [0,1)
raw_values = rng.step() # Returns 4 raw 32-bit integers
Structs
-
Random
: A high-performance random number generator using the Philox algorithm.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!