I am using Chainlink VRF V2 to generate 10 random numbers.

Assuming VRF generated something like this below.

[ 111.., 222.., 333.., 444.., 555.. 666.., 777.., 888.., 999.., 000..]

As best practice to generate within a range, for example from 1-50

for (uint32 i = 0; i < randomNumbers.length; i++) {
   randomRange = (randomNumbers[i] % 50) + 1

I need to generate 10 unique values based on the range, in my case 1-50.

The question is, how can I ensure that there will be no duplicates on the calculated random values?

Thanks for the help.

1 Answer 1


Please refer to this answer: How to guarantee unique number combinations based on Chainlink VRFv2?

The basic idea is to store unique numbers in an array, and then use the verified random number returned by VRF as a seed to shuffle the numbers in the array.

Once the shuffle is done, you can consider the numbers in the array as distinct random numbers because the sequence of numbers is decided by a random number.

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.