I'm working on a solidity contract that leverages random numbers through the use of Oracles. (ChainLink). Obviously given the price and the time it takes to get a random number I'm looking for the best ways to reuse that seed to generate more than 1 random number.
I have the following code which is supposed to generate 2 random numbers per loop 1 between 0 and 99 and the other one between 0 and 2. So a total of 20 random numbers in this example.
uint256 randomness = 78076127350936886139585537764964110448646985064549445555744769369952641998556;
for (uint256 i = 0; i < 10; i++) {
uint8 random1 = SafeCast.toUint8((randomness % (100 + i)) % 100)
uint8 random2 = SafeCast.toUint8((randomness % (100 + i)) % 3)
}
Seems to work okay but wanted to make sure if that made sense math wise or if there was a better way of doing this.
Aucun commentaire:
Enregistrer un commentaire