mercredi 24 novembre 2021

Generating several random numbers in one transaction (Solidity)

Is there a way to generate several random numbers in a single transaction? Let's suppose I have this code:

function example(uint _prop) public{
    while(random(100) < _prob){
      // Do something  
    }
}

The condition of the while loop depends on the random number chosen in each iteration. Is it possible to do this with VRF (Chainlink)? Or can only one random number be generated for each transaction?

For now I'm using this solution:

function random(uint _interval) internal returns (uint) {
    nonce++;
    return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, nonce))) % _interval;
}

but I know this is not a random number... This serves my purpose, but it is not formal. I want to improve it.




Aucun commentaire:

Enregistrer un commentaire