My goal is to generate around 1500 distinct random numbers, from range 8000.
I receive (blockchain ChainLink VRF - connected to random oracle, but that's not important):
- variable array of uint256[]
randomValues: unsigned values <0, 2^256-1> - i convert this field right away to numbers from my range, using
( randomValues[i] MOD 8000 ) + 1. - Since I want to create distinct numbers, I guess I should be calling generating function until I have enough of them.
My question is if you know about more efficient way how to generate array of distinct random numbers from array of numbers like [ 106182753482634914995248705155707514089551099076291415270692202660364749508656, 45628802998066180854454684078101263717187335597784096973096012883499998820379, .. ]?
expandedValues = new uint256[](n); for (uint256 i = 0; i < n; i++) { expandedValues[i] = (uint256(keccak256(abi.encode((randomNumber) + 1, i))) % 8000) + 1; }– wtdmn Jan 26 '22 at 14:33