Random¶
Pseudo-random number generation utilities.
Module: Std::Random
Summary¶
RandomInt8(min: int8, max: int8, seed: uint64) -> int8
RandomInt16(min: int16, max: int16, seed: uint64) -> int16
RandomInt32(min: int32, max: int32, seed: uint64) -> int32
RandomInt64(min: int64, max: int64, seed: uint64) -> int64
RandomInt(min: int, max: int, seed: uint64) -> int
RandomUInt8(min: uint8, max: uint8, seed: uint64) -> uint8
RandomUInt16(min: uint16, max: uint16, seed: uint64) -> uint16
RandomUInt32(min: uint32, max: uint32, seed: uint64) -> uint32
RandomUInt64(min: uint64, max: uint64, seed: uint64) -> uint64
RandomUInt(min: uint, max: uint, seed: uint64) -> uint
RandomFloat32(min: float32, max: float32, seed: uint64) -> float32
RandomFloat64(min: float64, max: float64, seed: uint64) -> float64
RandomBool(seed: uint64) -> bool
Description¶
The Std::Random module provides deterministic pseudo-random number generation functions for integer, floating-point, and boolean values.
All functions require an explicit seed value.
Using the same seed will always produce the same result.
Integer Random Numbers¶
RandomInt8¶
Returns a pseudo-random int8 value in the range [min, max).
RandomInt16¶
Returns a pseudo-random int16 value in the range [min, max).
RandomInt32¶
Returns a pseudo-random int32 value in the range [min, max).
RandomInt64¶
Returns a pseudo-random int64 value in the range [min, max).
RandomInt¶
Returns a pseudo-random platform-sized integer in the range:
Unsigned Integer Random Numbers¶
RandomUInt8¶
Returns a pseudo-random uint8 value in the range [min, max).
RandomUInt16¶
Returns a pseudo-random uint16 value in the range [min, max).
RandomUInt32¶
Returns a pseudo-random uint32 value in the range [min, max).
RandomUInt64¶
Returns a pseudo-random uint64 value in the range [min, max).
RandomUInt¶
Returns a pseudo-random platform-sized unsigned integer in the range:
Floating-Point Random Numbers¶
RandomFloat32¶
Returns a pseudo-random float32 value between min and max.
Example¶
RandomFloat64¶
Returns a pseudo-random float64 value between min and max.
Example¶
Boolean Random Numbers¶
RandomBool¶
Returns either true or false.
Example¶
Examples¶
Random Integer¶
Possible result:
Random Floating-Point Number¶
Possible result:
Random Boolean¶
Possible result:
Errors¶
All range-based functions require:
If min >= max, the function terminates the program with:
Notes¶
- All functions are deterministic.
- The same seed always produces the same result.
- Different seeds generally produce different results.
- Integer functions generate values in the range
[min, max). - Floating-point functions generate values between
minandmax. RandomBool()uses the least significant bit of the generated value.RandomSeed()is planned for a future release
Implementation Notes¶
The module currently uses an internal Xorshift-style pseudo-random number generator.
This generator is:
- Fast
- Deterministic
- Suitable for simulations, testing, and games
It is not cryptographically secure and should not be used for:
- Password generation
- Cryptographic keys
- Security-sensitive randomness
- Authentication tokens
For security-sensitive applications, use a cryptographically secure random source instead.