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] = min_finite[dtype](), max: Scalar[dtype] = max_finite[dtype]()) -> 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.__init__[Scalar[DType.uindex]](SIMD[DType.uindex, 1](min_or_neg_inf[DType.uindex]())), max: UInt = UInt.__init__[Scalar[DType.uindex]](SIMD[DType.uindex, 1](max_or_inf[DType.uindex]()))) -> 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
rand_int(mut self, *, min: Int = Int.__init__[Scalar[DType.index]](SIMD[DType.index, 1](min_or_neg_inf[DType.index]())), max: Int = Int.__init__[Scalar[DType.index]](SIMD[DType.index, 1](max_or_inf[DType.index]()))) -> Int
Returns a random Int from the given range.
Args:
Returns:
Int: A random Int in the range [min, max].
Raises:
If the underlying random number generator raises an error.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!