INNER CODE UNIT · C#

range

sdrapkin/SecurityDriven.Inferno · CryptoRandom.cs:113

			ulong range = (ulong)(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.
			ulong mask = range;
			mask |= mask >> 01;
			mask |= mask >> 02;
			mask |= mask >> 04;
			mask |= mask >> 08;
			mask |= mask >> 16;
			mask |= mask >> 32;

			ulong result;
			do
			{
				result = (ulong)GetRandomLong() & mask;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…