public int UniformInt(int maxExclusive)
{
if (maxExclusive < 0) {
throw new ArgumentException("maxExclusive (" + maxExclusive +
") is less than 0");
}
if (maxExclusive <= 0) {
return 0;
}
var b = new byte[4];
switch (maxExclusive) {
case 2: {
this.valueIrg.GetBytes(b, 0, 1);
return b[0] & 1;
}
case 256: {
this.valueIrg.GetBytes(b, 0, 1);
return (int)b[0] & 1;
}
default: {
while (true) {
var ib = 0;
if (maxExclusive == 0x1000000) {
this.valueIrg.GetBytes(b, 0, 3);
ib = b[0] & 0xff;
ib |= (b[1] & 0xff) << 8;
ib |= (b[2] & 0xff) << 16;
return ib;
}
if (maxExclusive == 0x10000) {
this.valueIrg.GetBytes(b, 0, 2);
ib = b[0] & 0xff;
ib |= (b[1] & 0xff) << 8;
return ib;
}
int maxexc;
maxexc = (maxExclusive <= 100) ? 2147483600 :
((Int32.MaxValue / maxExclusive) * maxExclusive);
while (true) {
this.valueIrg.GetBytes(b, 0, 4);
ib = b[0] & 0xff;
ib |= (b[1] & 0xff) << 8;
ib |= (b[2] & 0xff) << 16;
ib |= (b[3] & 0x7f) << 24;
if (ib < maxexc) {
return ib % maxExclusive;
}
}
}
}
}
}