Random¶
The Random
trait should be implemented by all random number generators. The
only method you need to implement is fun ref next(): U64
. Once that method
has been implemented, the Random
trait provides default implementations of
conversions to other number types.
Constructors¶
create¶
Create with the specified seed. Returned values are deterministic for a given seed.
Parameters¶
Returns¶
- Random ref^
Public Functions¶
has_next¶
If used as an iterator, this always has another value.
Returns¶
- Bool val
next¶
A random integer in [0, 2^64)
Returns¶
- U64 val
u8¶
A random integer in [0, 2^8)
Returns¶
- U8 val
u16¶
A random integer in [0, 2^16)
Returns¶
- U16 val
u32¶
A random integer in [0, 2^32)
Returns¶
- U32 val
u64¶
A random integer in [0, 2^64)
Returns¶
- U64 val
u128¶
A random integer in [0, 2^128)
Returns¶
- U128 val
ulong¶
A random integer in [0, ULong.max_value()]
Returns¶
- ULong val
usize¶
A random integer in [0, USize.max_value()]
Returns¶
- USize val
i8¶
A random integer in [-2^7, 2^7)
Returns¶
- I8 val
i16¶
A random integer in [-2^15, 2^15)
Returns¶
- I16 val
i32¶
A random integer in [-2^31, 2^31)
Returns¶
- I32 val
i64¶
A random integer in [-2^63, 2^63)
Returns¶
- I64 val
i128¶
A random integer in [-2^127, 2^127)
Returns¶
- I128 val
ilong¶
A random integer in [ILong.min_value(), ILong.max_value()]
Returns¶
- ILong val
isize¶
A random integer in [ISize.min_value(), ISize.max_value()]
Returns¶
- ISize val
int_fp_mult[optional N: ((U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val) & Real[N] val)]¶
A random integer in [0, n)
fun ref int_fp_mult[optional N: ((U8 val | U16 val | U32 val |
U64 val | U128 val | ULong val |
USize val) & Real[N] val)](
n: N)
: N
Parameters¶
- n: N
Returns¶
- N
int[optional N: ((U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val) & Real[N] val)]¶
A random integer in [0, n)
Uses fixed-point inversion if platform supports native 128 bit operations otherwise uses floating-point multiplication.
fun ref int[optional N: ((U8 val | U16 val | U32 val |
U64 val | U128 val | ULong val |
USize val) & Real[N] val)](
n: N)
: N
Parameters¶
- n: N
Returns¶
- N
int_unbiased[optional N: ((U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val) & Real[N] val)]¶
A random integer in [0, n)
Not biased with small values of n
like int
.
fun ref int_unbiased[optional N: ((U8 val | U16 val | U32 val |
U64 val | U128 val | ULong val |
USize val) & Real[N] val)](
n: N)
: N
Parameters¶
- n: N
Returns¶
- N
real¶
A random number in [0, 1)
Returns¶
- F64 val
shuffle[A: A]¶
Shuffle the elements of the array into a random order, mutating the array.
Parameters¶
- array: Array[A] ref
Returns¶
- None val