SKALE RNG
Background
Verifiable Random Functions (VRF) is commonly used across many applications both Web2 and Web3. However, within the Web3 space; attaining consensus on a random value is impossible to do on your average network that has consensus because there is no way to have every machine have the same value. The differing values would make functions run differently and consensus impossible.
Chainlink VRF has been the solution for most applications that require on-chain verified random values; however, this comes with a cost in both complexity and operating overhead. With VRF being in-general very expensive and requiring a complicated callback system; building in Web3 with SKALE RNG is a game-changer.
Access random numbers secured by the same network you trust for consensus, in-line, no wait, 100% free.
Install SKALE RNG
Using SKALE RNG
API
Solidity API
RNG
A contract to generate random numbers using the SKALE Network RNG endpoint. The RNG endpoint code for the function getRandomBytes() is taken from the SKALE Network Documentation: https://docs.skale.network/tools/skale-specific/random-number-generator
getRandomBytes
Fetches 32 random bytes from the SKALE Network RNG endpoint.
The assembly code retrieves random bytes from the SKALE Network. For more details on how it works, refer to the SKALE Network documentation: https://docs.skale.network/tools/skale-specific/random-number-generator
Return Values
Name | Type | Description |
---|---|---|
addr | bytes32 | A 32-byte random value. |
getRandomNumber
Generates a random number.
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | A random number as a uint256. |
getNextRandomNumber
Generates a random number with an additional index iteration. This should be used for multiple values in the same block.
Parameters
Name | Type | Description |
---|---|---|
nextIndex | uint256 | The index to iterate the RNG value by. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | A random number as a uint256. |
getNextRandomRange
Generates a random number within a specified range with an additional index iteration. This should be used for multiple values in the same block.
Parameters
Name | Type | Description |
---|---|---|
nextIndex | uint256 | The index to iterate the RNG value by. |
max | uint256 | The maximum value (inclusive) that the random number can be. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | A random number between 0 and max (inclusive). |
getRandomRange
Generates a random number within a specified range.
Parameters
Name | Type | Description |
---|---|---|
max | uint256 | The maximum value (inclusive) that the random number can be. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | A random number between 0 and max (inclusive). |