Hello,
I found this code while searching for solution to random number generation for a Dice roll.
function fulfillRandomness(bytes32 requestId, uint256 randomness) external override {
uint256 d6Result = randomness.mod(6).add(1);
emit RequestRandomnessFulfilled(requestId, randomness);
}
The above code is created using Chainlink’s Random number generator Smart Contract. I would like to understand this specific code in that section:
randomness.mod(6).add(1);
How does the above code work? What is mod() function over here. Does this return random number only between 1 to 6 or 0 to 5 ? If I need to get a random numbers between 1 to 3, which is 1 or 2 or 3, should I use the following line? Is it correct?
randomness.mod(3).add(1);
Thank you.
Regards,
Harish