Compute the next random value using the Central Limit Theorem,
which states that the averages of sets of uniformly-distributed
random values are normally distributed.
427497
public float nextCentral() {
        // Average 12 uniformly-distributed random values.
        float sum = 0.0f;
        for (int j = 0; j < 12; ++j)
            sum += gen.nextFloat();
        
        // Subtract 6 to center about 0.
        return stddev*(sum - 6) + mean;
    }
633224
def probability_gt(self, x):
        
        if self.mean is None:
            return
        p = normdist(x=x, mu=self.mean, sigma=self.standard_deviation)
        return 1-p
795237
function rand() {
  m_z = (36969 * (m_z & 65535) + (m_z >> 16)) & mask;
  m_w = (18000 * (m_w & 65535) + (m_w >> 16)) & mask;
  let result = ((m_z << 16) + m_w) & mask;
  result /= 4294967296;
  return result + 0.5;
}
1000026
public double[] sample(int numSamples, Random rand)
    {
        double[] samples = new double[numSamples];
        for(int i = 0; i < samples.length; i++)
            samples[i] = invCdf(rand.nextDouble());
        
        return samples;
    }
1304263
@SuppressWarnings("unchecked")
  // This is not good code, but what's there to be done? TODO
  public static <T> T sample(Counter<T> c, Random rand) {
    Iterable<T> objects;
    Set<T> keySet = c.keySet();
    objects = c.keySet();
    if (rand == null) {
      rand = new Random();
    } else { // TODO: Seems like there should be a way to directly check if T is
             // comparable
      if (!keySet.isEmpty() && keySet.iterator().next() instanceof Comparable) {
        List l = new ArrayList<T>(keySet);
        Collections.sort(l);
        objects = l;
      } else {
        throw new RuntimeException("Results won't be stable since Counters keys are comparable.");
      }
    }
    double r = rand.nextDouble() * c.totalCount();
    double total = 0.0;

    for (T t : objects) { // arbitrary ordering
      total += c.getCount(t);
      if (total >= r)
        return t;
    }
    // only chance of reaching here is if c isn't properly normalized, or if
    // double math makes total<1.0
    return c.keySet().iterator().next();
  }
811096
public double computeProbability(double mean, double sd, double value) {
		sd = sd + 0.00001;
		double probability = 0.0;
		double diff = value - mean;
		if (sd > 0.0) {
			 	double k = (Math.abs(value - mean)/sd);
			 	if (k > 1.0) {
			 		probability = 1.0/(k*k);
			 	}
			 	else {
			 		probability=  Math.exp(-(diff * diff / (2.0 * sd * sd)));
			 	}
		 }
		return probability;
	}
316127
private static double scoreToPvalue(double score, int n) {
        /*
        if(n<=20) {
            //calculate it from binomial distribution
        }
        */
        
        double mean=n*(n+1.0)/4.0;
        double variable=n*(n+1.0)*(2.0*n+1.0)/24.0;

        double z=(score-mean)/Math.sqrt(variable);

        return ContinuousDistributions.gaussCdf(z);
    }
232753
def randints(s, e, n=1):
        
        assert e >= s, "Wrong range: [{}, {})".format(s, e)
        n = max(1, n)
        arr = [s + a % (e - s) for a in struct.unpack('<%dL' % n, os.urandom(4 * n))]
        return arr
329934
def rnormal(mu, tau, size=None):
    
    return np.random.normal(mu, 1. / np.sqrt(tau), size)
128016
def generateAmplitudes(k):
    """"""
    res = np.array([np.random.random() for i in range(k)])
    return res/res.sum()
705279
static int getRandomInt(int min, int max, Random random) {
		// Use random.nextInt as it guarantees a uniform distribution
		int maxForRandom = max - min + 1;
		return random.nextInt(maxForRandom) + min;
	}
595792
function randn() {
  var u, v, s;
  do {
    u = Math.random() * 2 - 1;
    v = Math.random() * 2 - 1;
    s = u * u + v * v;
  } while (s >= 1 || s == 0);
  s = Math.sqrt(-2 * Math.log(s) / s);
  return u * s;
}
1290134
public static double normalDistribution(Double x, AssociativeArray params) {
        double mean= params.getDouble("mean");
        double variance= params.getDouble("variance");

        //standardize the x value
        double z=(x-mean)/Math.sqrt(variance);

        return ContinuousDistributions.gaussCdf(z);
    }
832672
public static void randomizeGaussian(MutableDoubleTuple t, Random random)
    {
        for (int i=0; i<t.getSize(); i++)
        {
            double value = random.nextGaussian();
            t.set(i, value);
        }
    }
379393
def _gauss(mean: int, sigma: int) -> int:
        
        return int(random.gauss(mean, sigma))
174602
public double computeProbability(double mean, double sd, double value) {
        double probability = 0.0;
        
      /* double diff = value - mean;
        if (sd > 0.0) {
            double k = (Math.abs(value - mean) / sd);
            if (k > 1.0) {
                probability = 1.0 / (k * k); // Chebyshev's inequality
            } else {
                probability = Math.exp(-(diff * diff / (2.0 * sd * sd)));
            }
        }*/
        
        if (sd > 0.0) {
            double k = (Math.abs(value - mean) / sd); // One tailed variant of Chebyshev's inequality
        	probability= 1.0 / (1+k*k); //cantelli's (one-tailed)
        	double var=Math.pow(sd, 2);
        	probability= 2*var/(var+Math.pow(Math.abs(value - mean), 2));
        	//probability= 1.0 / (1+k*k);
            //probability= 1.0 / (k*k); //chebyshev
        	//normal distribution
        	//double diff = value - mean;
        	//probability = Math.exp(-(diff * diff / (2.0 * sd * sd)));
        }
        
        return probability;
    }
968978
def pick(self):
        
        v = random.uniform(0, self.ub)
        d = self.dist
        c = self.vc - 1
        s = self.vc
        while True:
            s = s / 2
            if s == 0:
                break
            if v <= d[c][1]:
                c -= s
            else:
                c += s
                # we only need this logic when increasing c
                while len(d) <= c:
                    s = s / 2
                    c -= s
                    if s == 0:
                        break
        # we may have converged from the left, instead of the right
        if c == len(d) or v <= d[c][1]:
            c -= 1
        return d[c][0]