Mojo struct
Rng
struct Rng
A seeded pseudo-random number generator.
Users should not need to create this type directly, instead use the Rng
value provided by the Strategy trait.
Implemented traits
AnyType,
Movable,
UnknownDestructibility
Aliases
__del__is_trivial
alias __del__is_trivial = True
__moveinit__is_trivial
alias __moveinit__is_trivial = True
Methods
rand_bool
rand_bool(mut self, *, true_probability: Float64 = 0.5) -> Bool
Returns a random Bool with the given probability of being True.
Args:
- true_probability (
Float64): The probability of beingTrue(between 0.0 and 1.0).
Returns:
Bool: A random Bool.
Raises:
If the underlying random number generator raises an error.
rand_scalar
rand_scalar[dtype: DType](mut self, *, min: Scalar[dtype] = Scalar[dtype].MIN_FINITE, max: Scalar[dtype] = Scalar[dtype].MAX_FINITE) -> Scalar[dtype]
Returns a random Scalar from the given range.
Parameters:
- dtype (
DType): TheDTypeof the scalar.
Args:
Returns:
Scalar: A random number in the range [min, max].
Raises:
If the minimum value is greater than the maximum value or if the underlying random number generator raises an error.
rand_uint
rand_uint(mut self, *, min: UInt = UInt.MIN, max: UInt = UInt.MAX) -> UInt
Returns a random UInt from the given range.
Args:
Returns:
UInt: A random UInt in the range [min, max].
Raises:
If the underlying random number generator raises an error.
rand_int
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!