//generates up to 8 true random number values between mix and max value (0 and FFFF(4,294,967,295) possible) //returns INVALID_RANDOM if generated number has modulo bias (outside of uint32 range of valid values) //splits up the block.rand into chunks of 8 bytes and returns value uint48 constant INVALID_RANDOM = 44444444444; function getRandomSet( uint8 randomNumberCount, uint32 minValue, uint32 maxValue) public view returns(uint48[8] memory randomNumbers){ require(minValue < maxValue, "Min value not less than maxvalue"); require(randomNumberCount > 0 && randomNumberCount <=8, "Max of 8 total values."); uint48[8] memory randomNumberSet; bytes32 randomNumber = block.random; uint32 possibleValues = (maxValue - minValue) + 1; uint32 randVal; for(uint8 i = 0; i != randomNumberCount; i++){ randVal = (uint32(bytes4(randomNumber << 32 * i))); if(uint32(randVal) > (4294967295 / uint32(possibleValues)) * uint32(possibleValues)) //throw value out because it has modulo bias and makes odds uneven randomNumberSet[i] = INVALID_RANDOM; else randomNumberSet[i] = (randVal % possibleValues) + minValue; } //fill rest of values with invalid data for(uint8 i = randomNumberCount; i != 8; i++) randomNumberSet[i] = INVALID_RANDOM; return randomNumberSet; }