0

I am looking for the less gas consuming random number generator. I think i need an oracle but can you direct me to the best ?

Thanks

  • You might want to include what the random number generator will be used for... if the random number is not so sensitive, there are ways to generate pseudo-randomness for basically free on the blockchain. – Shawn Tabrizi Sep 17 '18 at 20:39
  • It is for a loterry. I think a pseudorandom is always dangerous. But maybe a precise idea ? – Nova Lova Sep 17 '18 at 21:08
  • 1
    Yes, for a lottery you definitely want to use an oracle. I only have experience with oraclize.it, so I will let others with more experience answer your question, but my understanding is that using "authenticity proofs", you and others can be certain that the random numbers generated are indeed generated by an independent 3rd party. – Shawn Tabrizi Sep 17 '18 at 21:11
-1

To generate a really good random number, you could use block hashes of future blocks. But that would require you to do two contracts call:

  • first contract call to "agree" which future block to take into account.
  • the second contract to actually use that block, which now is from the past.

An short example:

pragma solidity ^0.4.25;

contract RandomNumberReservation {
    uint public reservedBlockNumber;

    constructor(uint futureNthBlock) public {
        reservedBlockNumber = block.number + futureNthBlock;
    }

    function getCurrentBlockNumber() public view returns (uint) {
        return block.number;
    }

    function getRandomNumber() public view returns (bytes32) {
        require(block.number > reservedBlockNumber, "Time has not come yet");
        return blockhash(reservedBlockNumber);
    }
}
  • Oh thanks Miao. This method don't consume too much gas ? – Nova Lova Sep 17 '18 at 22:01
  • Each reservation would require a transaction. And after that you could retrieve the random number when Although you could write better version of that to save the amount of gas used for each transaction. I don't know how much is too much gas for you, but at least it wont' require you to use some external oracle services. – Miao ZhiCheng Sep 17 '18 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.