Java examples for java.lang:Math Number
Algorithm based on the random generation of Poissonian numbers, based on Knuth and Numerical Recipes (7.3.12).
//package com.java2s; public class Main { /**/*from w ww. j a v a2 s . c o m*/ * Algorithm based on the random generation of Poissonian numbers, * based on Knuth and Numerical Recipes (7.3.12). * * In the sources above, prob is actually a uniform random number * between 0-1, sampled each iteration. I have to make sure that * my alteration for a fixed value (to replace gene values) is * correct... * * @param lambda * @return */ static public int getPoisson(double prob, double lambda) { double L = Math.exp(-lambda); int k = 0; double p = 1; do { k++; p = p * prob; } while (p > L); // The original algorithm has k-1. We remove the -1 to guarantee // at least 1 event for every bin. return k; } }