prng
PRNG
This library is used to generate pseudorandom numbers
Not recommended for generating cryptographic secure randomness
PRNGState
Represents the state of the PRNG
struct PRNGState {
bytes32 state;
}
generateRandomHash
function generateRandomHash(struct PRNG.PRNGState self) internal returns (bytes32)
Generate a new pseudorandom hash
Takes the current state, hashes it and returns the new state.
Parameters
Name | Type | Description |
---|---|---|
self | struct PRNG.PRNGState | The PRNGState struct to use and alter the state |
Return Values
Name | Type | Description |
---|---|---|
[0] | bytes32 | The generated pseudorandom hash |
generateRandomNumber
function generateRandomNumber(struct PRNG.PRNGState self) internal returns (uint256)
Generate a new pseudorandom number
Takes the current state, hashes it and returns the new state.
Parameters
Name | Type | Description |
---|---|---|
self | struct PRNG.PRNGState | The PRNGState struct to use and alter the state |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The generated pseudorandom number |
generateRandomNumberInRange
function generateRandomNumberInRange(struct PRNG.PRNGState self, uint256 min, uint256 max) internal returns (uint256)
Generate a new pseudorandom number in a given range [min, max)
Takes the current state, hashes it and returns the new state. It constrains the returned number to the bounds of min (inclusive) and max (exclusive).
Parameters
Name | Type | Description |
---|---|---|
self | struct PRNG.PRNGState | The PRNGState struct to use and alter the state |
min | uint256 | |
max | uint256 |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The generated pseudorandom number constrained to the bounds of [min, max) |
seed
function seed(struct PRNG.PRNGState self, bytes32 entropy) internal
Seed the PRNG
The seed should not be zero
Parameters
Name | Type | Description |
---|---|---|
self | struct PRNG.PRNGState | The PRNGState struct to update the state |
entropy | bytes32 | The seed value (entropy) |