Rationale
The current implementation for drawing uniformly random numbers in a given range is based on rejection sampling, see
|
for (result = n; result >= n; result = read(src, bits)) {} |
The associated gas costs are therefore not fixed but might vary from call to call depending on the required iterations. This makes gas cost estimations unreliable because the state of the random source might change until a given transaction is included in a block. In the worst case, this could lead to failing transactions.
Potential solution
Change to a random number sampling scheme with constant gas cost.
I did not do any proper research on potential algorithms yet, but one that comes to mind would be modulus sampling result = BigUniformRand % n - trading exact uniformity (introducing mod biases) for a constant gas cost.
Rationale
The current implementation for drawing uniformly random numbers in a given range is based on rejection sampling, see
ethier/contracts/random/PRNG.sol
Line 153 in a0b71a9
The associated gas costs are therefore not fixed but might vary from call to call depending on the required iterations. This makes gas cost estimations unreliable because the state of the random source might change until a given transaction is included in a block. In the worst case, this could lead to failing transactions.
Potential solution
Change to a random number sampling scheme with constant gas cost.
I did not do any proper research on potential algorithms yet, but one that comes to mind would be modulus sampling
result = BigUniformRand % n- trading exact uniformity (introducing mod biases) for a constant gas cost.