BlockHashRNG
Inherits: RNG
Author: Clément Lesaege - clement@lesaege.com Random Number Generator returning the blockhash with a fallback behaviour. In case no one called it within the 256 blocks, it returns the previous blockhash. This contract must be used when returning 0 is a worse failure mode than returning another blockhash. Allows saving the random number for use in the future. It allows the contract to still access the blockhash even after 256 blocks.
State Variables
randomNumbers
mapping(uint256 => uint256) public randomNumbers;
Functions
requestRandomness
Request a random number.
function requestRandomness(uint256 _block) external override;
Parameters
Name | Type | Description |
---|---|---|
_block | uint256 | Block the random number is linked to. |
receiveRandomness
Return the random number. If it has not been saved and is still computable compute it.
function receiveRandomness(uint256 _block) external override returns (uint256 randomNumber);
Parameters
Name | Type | Description |
---|---|---|
_block | uint256 | Block the random number is linked to. |
Returns
Name | Type | Description |
---|---|---|
randomNumber | uint256 | The random number or 0 if it is not ready or has not been requested. |