Witam, znalazłem w sieci metodę która losuje liczby z podanego przedziału, metoda działa znakomicie, mam jednak problem ze zrozumieniem części kodu, bardzo proszę o wyjaśnienie operacji wykonywanych w pętli while. Z góry dziękuję za pomoc.
public override Int32 Next(Int32 minValue, Int32 maxValue)
{
if (minValue > maxValue)
throw new ArgumentOutOfRangeException("minValue");
if (minValue == maxValue) return minValue;
Int64 diff = maxValue - minValue;
while (true)
{
_rng.GetBytes(_uint32Buffer);
UInt32 rand = BitConverter.ToUInt32(_uint32Buffer, 0);
Int64 max = (1 + (Int64)UInt32.MaxValue);
Int64 remainder = max % diff;
if (rand < max - remainder)
{
return (Int32)(minValue + (rand % diff));
}
}
}