PeterO.RandomGenerator.Hypergeometric C# (CSharp) Method

Hypergeometric() public method

Conceptually, given a set of tokens, some of which are labeled 1 and the others labeled 0, draws "trials" tokens at random without replacement and then counts the number of 1's drawn.
public Hypergeometric ( int trials, int ones, int count ) : int
trials int The number of tokens drawn at random without /// replacement.
ones int The number of tokens labeled 1.
count int The number of tokens labeled 1 or 0.
return int
        public int Hypergeometric(int trials, int ones, int count)
        {
            if (ones < 0) {
            throw new ArgumentException("ones (" + ones + ") is less than 0");
              }
              if (ones > count) {
            throw new ArgumentException("ones (" + ones + ") is more than " +
              count);
              }
              if (count < 0) {
            throw new ArgumentException("count (" + count +
              ") is less than 0");
              }
              if (trials < 0) {
            throw new ArgumentException("trials (" + trials +
              ") is less than 0");
              }
              if (trials > count) {
            throw new ArgumentException("trials (" + trials +
              ") is more than " + count);
              }
              var ret = 0;
              for (var i = 0; i < trials && ones > 0; ++i) {
            if (this.UniformInt(count) < ones) {
              --ones;
              ++ret;
            }
            --count;
              }
              return ret;
        }