- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
class RandomGeneratorFiveState : RandomGenerator {
int zero, one, two, three, four, min, max;
public RandomGeneratorFiveState(int min, int zero, int one, int two, int three, int four)
: base() {
max = min + (four != 0 ? 4 : three != 0 ? 3 : two != 0 ? 2 : one != 0 ? 1 : 0);
this.min = min;
this.zero = zero;
this.one = this.zero + one;
this.two = this.one + two;
this.three = this.two + three;
this.four = this.three + four;
}
public override int Next() {
int n = Random.Next(four);
if(n < zero) return min;
if(n < one) return min + 1;
if(n < two) return min + 2;
if(n < three) return min + 3;
return min + 4;
}
public override int GetMax() { return max; }
public override int GetMin() { return min; }
}