INNER CODE UNIT · C#
range
sdrapkin/SecurityDriven.Inferno · CryptoRandom.cs:194
uint range = (uint)(maxValue - minValue) - 1;
// If there is only one possible choice, nothing random will actually happen, so return the only possibility.
if (range == 0) return minValue;
// Create a mask for the bits that we care about for the range. The other bits will be masked away.
uint mask = range;
mask |= mask >> 01;
mask |= mask >> 02;
mask |= mask >> 04;
mask |= mask >> 08;
mask |= mask >> 16;
uint result;
do
{
result = (uint)GetRandomInt() & mask;
} while (result > range);