WitnetRandomness
contract, also known as the Β«Witnet Randomness OracleΒ», is the easiest and most convenient way to generate EVM-agnostic and realiable randomness for your smart contracts.WitnetRandomness
in practically all the EVM-compatible chains supported by the Witnet oracle.WitnetRandomness
contract internally uses an instance of the low-level WitnetRequestRandomness
formarly explained, this contract implements also the whole request/resolution asynchronous flow involved in the resolution of a data request in the context of the Witnet side-chain.WitnetRandomness
you just need to:randomize() payable
.isRandomized(uint256)
and getRandomnessAfter(uint256)
.WitnetRandomness
contract is not owned, so anyone is actually allowed to either request new randomness (i.e. randomize()
), or get previously solved randomness from storage (i.e. isRandomized(uint _blockNumber)
, getRandomnessAfter(uint _blockNumber)
).randomize() payable
), even if other previous randomness requests (either coming from you, or other apps) were still pending to be solved.WitnetRandomness
contract is Clonable
, which means that you, or your contract, may cheaply create your own cloned copy as a means to gain ownership of the self-contained WitnetRequestRandomness
contract. Only the owner of a cloned copy will be allowed to change the witnessing parameters of the low-level Randomness Request.WitnetRandomness
contract provides the random(uint32 _range, uint256 _nonce, uint256 _block)
and random(uint32 _range, uint256 _nonce, bytes32 _seed)
helper functions.random(..)
functions guarantee that different contracts/apps reading from same randomness request will actually get completely different random sequences of uniformly distributed numbers, within a given range, and doing so while keeping complexity under O(1) (π).WitnetRandomness
contract guarantees that the received randomness is the one requested for a given block number, or the subsequent randomness request posted after the given block if there was none posted back then, or if the ones posted after that got reverted for whatever reason at the Witnet side-chain level.randomize() payable
, you should not allow any change in your smart contract state that alters the outcome of whatever the requested randomness is planned to be used for.isRandomized(uint256)
method, passing the block number at which the randomize() payable
call got mined, as to check for readiness of the requested randomness.WitnetRandomness
contract is not owned, the self-contained WitnetRequestRandomness
instance it is (i.e. witnetRandomnessRequest()
). This enables the operator of aWitnetRandomness
instance to eventually update the witnessing parameters of the underlying low-level Randomenss Request that gets posted to the Witnet side-chain. WitnetRequestRandomness
instance (accesible via the template()
method), will foerever remain immutable, though.WitnetRequestRandomness
instance may eventually turn immutable at the time the WitnetRandomness
operator decides to renounce its ownership.WitnetRandomness
operator modify the underlying witnessing parameters of the randomness request, is left open as to provide a means for adapting to eventual high-load situations within the Witnet oracle's side-chain.