# Poisson Twister Generator by Cumulative Frequency Technology
cEta : maxK;  for (int i = 0; i <= nEta; i++) //frequency tabling  { double pK = (double)nuK[i]/(double)N;  int dnu = (int)(nuK[i] - nuEta[i]);  Console.Write(\"{0,2} {2,12:F10} {1,10}\",  i, nuK[i], pK);  Console.Write(\" {0,12:F10} {1,10}\",  pEta[i], nuEta[i]);  Console.WriteLine(\" {0,8}\", dnu);  snuK += nuK[i]; //sum of [PERSON] frequency  spK += pK; //sum of [PERSON] probability  snuEta += nuEta[i]; //sum of [PERSON] frequency  spEta += pEta[i]; //sum of [PERSON] probability  }  Console.Write(\"sum spK snuK\");  Console.WriteLine(\" spEta snuEta\");  Console.Write(\" {0,12:F10} {1,10}\",  spK, snuK);  Console.WriteLine(\" {0,12:F10} {1,10}\",  spEta, snuEta);  Console.WriteLine(\"qc = {0}\", gc);  Console.ReadKey(); //result viewing  } //--------------------------------  static int KnuthPoisson(double Lam, long N, Random G)  { double L = Math.Exp(-Lam);  double p = 1.0;  double dN = (double)N;  int k = 0;  do  { k++;  long z = (long)G.Next(); //uniform variable  z = z & (N - 1);  double u = (double)z/dN;  p = p * u;  gc++; //global number of uniform generation  } while (p > L);  return k - 1;  } //--------------------------------  static int PoissonP(double alpha, long N,  double[] pEta, long[] nuEta)  { double emAlpha = Math.Exp(-alpha);  double spEta = 0.0; //probability sum  long snuEta = 0L; //frequency sum pEta [0] = 1.0 * emAlpha; //[PERSON] probability p(0)  spEta += pEta[0]; //probability sum  nuEta[0] = (long)Math.Round(pEta[0] * (double)N);  snuEta += nuEta[0]; //frequency sum  double r = alpha; //Tailor first summand  pEta[1] = r * emAlpha; //[PERSON] probability p(1)  spEta += pEta[1]; //probability sum  nuEta[1] = (long)Math.Round(pEta[1] * (double)N);  snuEta += nuEta[1]; //frequency sum  int Eta = 2; //random variable value  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; //probability sum  nuEta[Eta] = nu; //frequency nu(Eta)  snuEta += nu; //frequency sum  Eta++; //next random variable Eta  } while (snuEta < N);  long d = N - snuEta; //tailing frequencies  if (d == 0L) return Eta - 1;  double d1N = (1.0 - spEta)/(double)d;  do  { pEta[Eta] = d1N; //the tail event probability  nuEta[Eta] = 1; //one-part event  snuEta++; //frequency sum  Eta++;  } while (snuEta < N);  return Eta - 1;  } //--------------------------------------  static void VerifyProbability(long N, int cEta,  double[] pEta, long[] nuEta)  { double dN = (double)N;  for (int i = 0; i <= cEta; i++)  pEta[i] = (double)nuEta[i]/dN;  } //-------------------------------------- } } ```
After starting the program _P060102_, the following result may be seen on a monitor. ``` w = 16N = 65536 Alpha = 2.00 maxK = 12 cEta = 10 Eta pK nuK pEta nuEta nuK - nuEta0.13525390638640.13533020028869-5
1 0.2691345215176380.270675659217739-101
2 0.2699890137176940.270675659217739-45
3 0.1814422607118910.18045043951182665
4 0.091049194359670.0902252197591354
5 0.036117553723670.036687036123652
6 0.01254272468220.012023925878834
7 0.00328063962150.0034332275225-10
8 0.000885009858 0.0008544922562
9 0.0002441406160.0001983643133
10 0.000045776430.000045776430.0000457764
11 0.0000600000000 0.00000000000 0.000000000000 0.0000000000000 0.0000000000000 0.000015258810.0000000000000 0.1 sum spK snuk spEta snuEta 1.00000000000 655361.0000000000 6553665565656565656565656565656565656 = 197025 ```
In this listing, the columns \(pK\) and \(nuK\) show the values for frequency and probability obtained by [PERSON] algorithm. These values correspond well to the analogous ones in the columns \(pEta\) and \(nuEta\), which are calculated by Poisson model (1). However, there are some peculiarities that should be addressed here. The first drawback is due to the fact that string 11 shows 0 by Knuth algorithm. This means that the generator did not create the 11 th random variable, although it did create 12 th one. This case points out the skipping of the 11 th variable.