1

I'm using chainlink to get a random number. I need a bunch more random numbers.

I'm currently using:

[
  uint256(keccak256(abi.encodePacked(randomNumber, nonce))),
  uint256(keccak256(abi.encodePacked(randomNumber, nonce + 1)))
];

But I wonder if there is anything gas-efficient techniques I should consider?

1 Answer 1

2

Please see the answer here. If you don't need the full whole number (quite likely), it should work for you.

To put it shortly: assuming you actually only need a limit of "a" for the first random number and "b" for the second number, and we'll mark Chainlink random number as x: first random number would be x % a, second number x / a % b, third number x / a / b % c, etc'.

To make it more efficient, first of all use bitwise operations instead of plain mod/div, and also use bitwise shift to efficiently reduce the number each iteration (instead of doing x / a / b).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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