Mojo module
random
Provides functions for pseudorandom numbers.
You can import these APIs from the random package. For example:
from std.random import seedThese functions use a shared, global pseudorandom number generator (PRNG) state. The global random state is shared across threads and concurrent access can cause race conditions and undefined behavior.
Warning: NOT cryptographically secure. This PRNG is suitable for simulations, games, and general statistical purposes, but shouldn't be used for security-sensitive applications such as generating passwords, authentication tokens, or encryption keys.
Functions
-
rand: Fills memory with random values from a uniform distribution. -
randint: Fills memory with uniformly distributed random integers in the range [low, high]. -
randn: Fills memory with random values from a Normal distribution. -
randn_float64: Returns a randomFloat64sampled from a normal distribution. -
random_float64: Returns a randomFloat64number from the given range [min, max). -
random_si64: Returns a randomInt64number from the given range [min, max]. -
random_ui64: Returns a randomUInt64number from the given range [min, max]. -
seed: Seeds the random number generator using a time-based value. -
shuffle: Shuffles the elements of the list randomly.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!