Random numbers

HPB's provable random numbers

A random number is generated for every block on HPB network. You can view random numbers being generated at https://hscan.org

Many chains use pseudo-random number generators which are deterministic. Others use oracles or solutions such as Chainlink VRF, which can be a hassle to set up, and can be prohibitively expensive to call. For example, calling a random number via Chainlink VRF on the Binance Smart Chain, currently costs 0.2 LINK, or over $2 (April 2022).

HPB is able to offer provable random numbers on-chain for FREE, thanks to its Hardware Random Number Generator (HRNG). This HRNG is a feature of the hardware accelerator (BOE) installed by each node operator in the HPB network. It senses tiny variances in voltage (as little as 0.00001 volts) in a component. This introduces a physical real world variable that makes HPB’s random numbers impossible to predict, so well suited to 100% fair lotteries and games of chance.

See the article Provable Random Numbers in Blockchain for more.

block.random is a Solidity value type, exclusive to HPB chain, whereby a random value will be published by a miner. block.random is currently only supported up to Solidity version 0.5.7, which makes it impossible to compile with the latest contract code (currently 0.8.11). There is a workaround.

Use a random number in a smart contract

To incorporate a random number into a smart contract, use this process:

  1. Deploy a smart contract using the block.random function call or simply reference an existing smart contract that pulls a random number. for example:

2. Create a new smart contract that references the first smart contract, to pull a random number. For example:

/ SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.7;
abstract contract HRNG {
   function getRandom() public view virtual returns (bytes32);}
contract RetrieveRandom {
address hrngAddr;
HRNG hrng;
   constructor (address hrngaddr) {
      hrngAddr = hrngaddr;
      hrng = HRNG(hrngAddr);
   }
   function retrieveNumber() public view returns (uint256) {
      uint256 random = uint256(hrng.getRandom());
      return random;
   }
} 

3. Finally, reference the first smart contract address when you deploy this new contract:

Last updated