RandomGenerator interfacev0.1.0
pub interface RandomGenerator {
func NextUint64(self: &var Self) -> uint64;
}
The single operation every generator supplies. Implementations must advance their own state, so the receiver is a mutable reference. Borrowed interface views and generic bounds both keep it the caller's state that advances.
Requirements
NextUint64
func NextUint64(self: &var Self) -> uint64
The next 64-bit word, and the state advanced past it.
Returns: the next 64 bits
Implementations
| Type | Summary |
|---|---|
SplitMix64 | The seeding generator: a fast mixer with a 64-bit state, used to spread one seed over a larger one. |
Pcg64Dxsm | A PCG64-DXSM generator. |
Xoshiro256 | A Xoshiro256** generator. |
Related
FillBytes<G>
pub func FillBytes<G: RandomGenerator>(
generator: &var G,
into: var char8[..]
)
Fills into with random bytes.
The words are consumed least significant byte first, and a partial final word contributes its low bytes and
discards the rest — so the same into.length always consumes the same number of words, and two runs that
fill buffers of the same size stay in step.
Type parameters
| Name | Description |
|---|---|
G: RandomGenerator | the generator's type |
Parameters
| Name | Type | Description |
|---|---|---|
generator | &var G | where the bits come from |
into | var char8[..] | receives the bytes |
NextUint32<G>
pub func NextUint32<G: RandomGenerator>(generator: &var G) -> uint32
The next 32-bit word: the low half of a 64-bit one. A whole word is consumed and half of it discarded, which costs nothing and keeps the word stream aligned -- a generator that handed out the halves in turn would produce different sequences depending on how many narrow draws happened to precede a wide one.
Type parameters
| Name | Description |
|---|---|
G: RandomGenerator | the generator's type |
Parameters
| Name | Type | Description |
|---|---|---|
generator | &var G | where the bits come from |
Returns: the next 32 bits
NextUint16<G>
pub func NextUint16<G: RandomGenerator>(generator: &var G) -> uint16
The next 16-bit word.
Type parameters
| Name | Description |
|---|---|
G: RandomGenerator | the generator's type |
Parameters
| Name | Type | Description |
|---|---|---|
generator | &var G | where the bits come from |
Returns: the next 16 bits
NextUint8<G>
pub func NextUint8<G: RandomGenerator>(generator: &var G) -> uint8
The next 8-bit word.
Type parameters
| Name | Description |
|---|---|
G: RandomGenerator | the generator's type |
Parameters
| Name | Type | Description |
|---|---|---|
generator | &var G | where the bits come from |
Returns: the next 8 bits
NextUint128<G>
pub func NextUint128<G: RandomGenerator>(generator: &var G) -> uint128
The next 128-bit word, high half drawn first.
Type parameters
| Name | Description |
|---|---|
G: RandomGenerator | the generator's type |
Parameters
| Name | Type | Description |
|---|---|---|
generator | &var G | where the bits come from |
Returns: the next 128 bits
NextFloat64<G>
pub func NextFloat64<G: RandomGenerator>(generator: &var G) -> float64
A float64 uniformly distributed in [0, 1).
Built from the top 53 bits of a word, which is exactly the number a float64 can hold without rounding: every
value produced is a multiple of 2^-53, each equally likely, and none is ever exactly one. Dividing a whole
word by 2^64 instead would round — and rounding upward at the top would produce exactly one, which callers
scaling into an array index do not expect.
Type parameters
| Name | Description |
|---|---|
G: RandomGenerator | the generator's type |
Parameters
| Name | Type | Description |
|---|---|---|
generator | &var G | where the bits come from |
Returns: a value in [0, 1), with 53 bits of significance
NextFloat32<G>
pub func NextFloat32<G: RandomGenerator>(generator: &var G) -> float32
A float32 uniformly distributed in [0, 1), from the top 24 bits.
Type parameters
| Name | Description |
|---|---|
G: RandomGenerator | the generator's type |
Parameters
| Name | Type | Description |
|---|---|---|
generator | &var G | where the bits come from |
Returns: a value in [0, 1), with 24 bits of significance