Skip to main content

Mojo struct

NormalRandom

struct NormalRandom[rounds: Int = 6]

A high-performance random number generator using the Box-Muller transform.

The Box-Muller transform is a method for generating pairs of independent standard normal random variables.

Parameters

  • rounds (Int): Number of mixing rounds to perform for the underlying random uniform generator that serves as input to the Box-Muller transform. Higher values provide better statistical quality at the cost of performance. Default is 6.

Implemented traits

AnyType, UnknownDestructibility

Aliases

__del__is_trivial

alias __del__is_trivial = True

Methods

__init__

__init__(out self, *, seed: SIMD[uint64, 1] = 0, subsequence: SIMD[uint64, 1] = 0, offset: SIMD[uint64, 1] = 0)

step_normal

step_normal(mut self, mean: SIMD[float32, 1] = 0, stddev: SIMD[float32, 1] = 1) -> SIMD[float32, 8]

Generate 8 normally distributed random numbers using Box-Muller transform.

Returns:

SIMD: SIMD vector containing 8 random float32 values from a normal distribution with mean mean and standard deviation stddev.

Was this page helpful?