# Poisson Twister Generator by Cumulative Frequency Technology
using nsDeonYuliTwist32D; //complete twister generator //of integer uniform numbers namespace P060202 { class cp060202 { static void Main(string[] args) { int w = 32; //bit width of uniform integer variable long N = 1L << w; //random variable quantity  Console.WriteLine(\"w = {0} N = {1}\", w, N);  double Alpha = 2.0;  Console.WriteLine(\"Alpha = {0:F2}\", Alpha);  int wX = 200;  double[] pEta = new double[wX]; //Poisson probability long[] nuEta = new long[wX]; //Poisson frequency long[] cnuEta = new long[wX]; //cumulative frequency  int cEta = PoissonDY(Alpha, pEta, nuEta, cnuEta, N);  VerifyProbability(N, cEta, pEta, nuEta, cnuEta);  Console.WriteLine(\"cEta = {0}\", cEta);  cDeonYuliTwist32D DYG = new cDeonYuliTwist32D();  DYG.SetW(w); //set bit width of uniform variable  DYG.Start(); //start uniform generator  long[] nuDYG = new long[wX];//frequencies of generator  for (int i = 0; i < wX; i++) nuDYG[i] = 0;  for (long j = 0; j < N; j++)  { long z = DYG.Next(); //uniform variable  int Eta = SearchEta(z, cnuEta, cEta);  nuDYG[Eta]++; //uniform variable counter  }  double spEta = 0.0; //sum of Poisson probability  long snuEta = 0; //sum of Poisson frequency  long snuDYG = 0; //sum of variables by generator  Console.Write(\"Eta pEta nuEta\");  Console.WriteLine(\" cnuEta nuDYG\");  for (int Eta = 0; Eta <= cEta; Eta++)  { Console.WriteLine(  \"{0,2} {1,12:F10} {2,10} {3,10} {4,10}\",  Eta, pEta[Eta], nuEta[Eta],  cnuEta[Eta], nuDYG[Eta]);  spEta += pEta[Eta];  snuEta += nuEta[Eta];  snuDYG += nuDYG[Eta];  }  Console.Write(\"Sum spEta snuEta\");  Console.WriteLine(\" snuDYG\");  Console.Write(\" {0,12:F10} {1,10}\",  spEta, snuEta);  Console.WriteLine(\" {0,10}\", snuDYG);  Console.ReadKey(); //result viewing  } //------------------------------------------------static int PoissonDY (double alpha, double[] pEta,  long[] nuEta, long[] muEta, long N)  { double emAlpha = Math.Exp(-alpha);  double spEta = 0.0; //sum of probability  long snuEta = 0L; //sum of frequency  pEta[0] = 1.0 * emAlpha; //Poisson probability p(0)  spEta += pEta[0]; //sum of probability  nuEta[0] = (long)Math.Round(pEta[0] * (double)N);  snuEta += nuEta[0]; //sum of frequency  cnuEta[0] = snuEta; //cumulative frequency cnu(0)  double r = alpha; //Tailor first summand  pEta[1] = r * emAlpha; //Poisson probability p(1)  spEta += pEta[1]; //sum of probability  nuEta[1] = (long)Math.Round(pEta[1] * (double)N);  snuEta += nuEta[1]; //sum of frequency  cnuEta[1] = snuEta; //cumulative frequency cnu(1)  int Eta = 2; //random variable  do  { r *= alpha/(double)Eta; //regular summand of exp  double p = r * emAlpha; //probability p(Eta)  long nu = (long)Math.Round(p * (double)N);  long sd = snuEta + nu;  if (nu == 0L || sd > N) break; //the tail  pEta[Eta] = p; //probability p(Eta)  spEta += p; //sum of probability  nuEta[Eta] = nu; //frequency nu(Eta)  snuEta += nu; //sum of frequency  cnuEta[Eta] = snuEta; //cumulative frequency  Eta++; //next random variable <=1 } while (snuEta < N);  Eta--;  long d = N - snuEta; //tailing frequencies  if (d == 0L) return Eta;  double d1N = (1.0 - spEta)/(double)d;  do  { Eta++;  pEta[Eta] = d1N; //probability of a tail event  nuEta[Eta] = 1; //one-frequency event  snuEta++; //sum of frequency  cnuEta[Eta] = snuEta; //cumulative frequency  } while (snuEta < N);  return Eta;  } //-------------------------------- static void VerifyProbability (long N, int cEta,  double[] pEta, long[] nuEta, long[] cnuEta)  { double dN = (double)N;  for (int i = 0; i <= cEta; i++)  pEta[i] = (double)nuEta[i]/dN;//------------------------------------------------

static int SearchEta (long z, long[] cnuEta, int cEta)

{ int Eta = 0;  for (; Eta <= cEta; Eta++)  if (z < cnuEta[Eta]) break;  return Eta;  }

//------------------------------------------------

After launching the program _P060202_ the following listing appears on the monitor.