Returns a random variate from the negative binomial distribution.

`size` must be strictly positive, and `prob` must be in `(0, 1]`.

@fullName rnbinom(size, prob)()
@memberof nbinom
10341
function rnbinom(size, prob) {
      var rg;

      if (size <= 0 || prob <= 0 || prob > 1) {
         return function() { return NaN; };
      }
      if (prob === 1) { return function() { return 0; }; }
      rg = rgamma(size, (1 - prob) / prob);
      return function() { return rpois(rg())(); };
   }
612686
function createRandom(n, min, max) {
    let scale = max - min;
    let array = [];
    for (var i = 0; i < n; i++) {
        array[i] = (Math.random() * scale) + min;
    }
    return new Vector(array);
}
1210029
public static BigInteger generateRandomIntegerLessThan(BigInteger num) {
        BigInteger r = null;
        while (r == null || r.compareTo(num) >= 0) {
            r = new BigInteger(num.bitLength(), RANDOM);
        }
        return r;
    }
1100857
def random_unit(size=3):
    
    while True:
        result = np.random.normal(0, 1, size)
        length = np.linalg.norm(result)
        if length > 1e-3:
            return result/length
204166
def rweibull(alpha, beta, size=None):
    
    tmp = -np.log(runiform(0, 1, size))
    return beta * (tmp ** (1. / alpha))
485897
function randnBM() {
  const u = 1 - Math.random() // Subtraction to flip [0, 1) to (0, 1].
  const v = 1 - Math.random()
  return Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v)
}
1362961
def sample(self, n):
        
        rg = self._ctx._jvm.org.apache.commons.math3.random.JDKRandomGenerator()
        return _java2py(self._ctx, self._jmodel.sample(n, rg))
150935
public static int binomial(RandomGenerator rng, int n, double p) {
        if ((p < 0) || (p > 1)) {
            return 0;
        }
        int c = 0;
        for (int i = 0; i < n; i++) {
            if (rng.nextDouble() < p) {
                c++;
            }
        }
        return c;
    }
472253
def rand_bool(p:float, size:Optional[List[int]]=None)->BoolOrTensor:
    ""
    return uniform(0,1,size)<p
587973
public static double negativeBinomial(int n, int r, double p) {
        //tested its validity with http://www.mathcelebrity.com/binomialneg.php
        if(n<0 || r<0 || p<0) {
            throw new IllegalArgumentException("All the parameters must be positive.");
        }
        n = Math.max(n,r);//obvisouly the total number of tries must be larger than the number of required successes
        
        double probability = Arithmetics.combination(n-1, r-1)*Math.pow(1-p,n-r)*Math.pow(p,r);
        
        return probability;
    }
416500
public static IntDoubleVector getRandomBernoulliDirection(int p) {
        IntDoubleVector e = new IntDoubleDenseVector(p);
        for (int i=0; i<p; i++) {
            // Bernoulli distribution chooses either positive or negative 1.
            e.set(i, (Prng.nextBoolean()) ? 1 : -1);
        }
        return e;
    }
206181
public T random() {

        long randomNum =
            ThreadLocalRandom.current().nextLong(
                toProlepticNumber(this.t1),
                toProlepticNumber(this.t2) + 1);
        return fromProlepticNumber(randomNum);

    }
335344
public static int[] randomPermutation(int size) {
        Random r = new Random();
        int[] result = new int[size];

        for (int j = 0; j < size; j++) {
            result[j] = j;
        }
        
        for (int j = size - 1; j > 0; j--) {
            int k = r.nextInt(j);
            int temp = result[j];
            result[j] = result[k];
            result[k] = temp;
        }

        return result;
    }
1286405
def get_random(self, size=10):
        
        # Sample random bin centers
        bin_centers_ravel = np.array(np.meshgrid(*self.bin_centers(),
                                                 indexing='ij')).reshape(self.dimensions, -1).T
        hist_ravel = self.histogram.ravel()
        hist_ravel = hist_ravel.astype(np.float) / np.nansum(hist_ravel)
        result = bin_centers_ravel[np.random.choice(len(bin_centers_ravel),
                                                    p=hist_ravel,
                                                    size=size)]

        # Randomize the position inside the bin
        for dim_i in range(self.dimensions):
            bin_edges = self.bin_edges[dim_i]
            bin_widths = np.diff(bin_edges)

            # Note the - 1: for the first bin's bin center, searchsorted gives 1, but we want 0 here:
            index_of_bin = np.searchsorted(bin_edges, result[:, dim_i]) - 1
            result[:, dim_i] += (np.random.rand(size) - 0.5) * bin_widths[index_of_bin]

        return result
511248
def miller_rabin(n, k, rnd=default_pseudo_random):
    '''
       
   '''
    s = 0
    d = n-1
    # Find nearest power of 2
    s = primitives.integer_bit_size(n)
    # Find greatest factor which is a power of 2
    s = fractions.gcd(2**s, n-1)
    d = (n-1) // s
    s = primitives.integer_bit_size(s) - 1
    while k:
        k = k - 1
        a = rnd.randint(2, n-2)
        x = pow(a, d, n)
        if x == 1 or x == n - 1:
            continue
        for r in range(1, s-1):
            x = pow(x, 2, n)
            if x == 1:
                return False
            if x == n - 1:
                break
        else:
            return False
    return True
103523
public int getRandomID() {
        //Compute the width of the partition...
        int partitionWidth;
        if (lowerID < upperID) partitionWidth = upperID - lowerID; //... for "proper" ranges
        else partitionWidth = (idUpperBound - lowerID) + upperID; //... and those that "wrap around"
        Preconditions.checkArgument(partitionWidth > 0, partitionWidth);
        return (random.nextInt(partitionWidth) + lowerID) % idUpperBound;
    }
661120
public static /*@pure@*/ double probToLogOdds(double prob) {

    if (gr(prob, 1) || (sm(prob, 0))) {
      throw new IllegalArgumentException("probToLogOdds: probability must " +
				     "be in [0,1] "+prob);
    }
    double p = SMALL + (1.0 - 2 * SMALL) * prob;
    return Math.log(p / (1 - p));
  }