LotGDocker/lotgd-web/lotgd/lib/bell_rand.php
2020-08-17 19:16:42 -04:00

631 lines
14 KiB
PHP
Executable File

<?php
// addnews ready
// translator ready
// mail ready
$bell_curve=0;
function bell_rand($min=false,$max=false){
global $bell_curve;
if ($min===false && $max===false) {
//no value passed, assume 0 min, and 1 max.
$min=0;
$max=1;
}
if ($max===false){ // here got something mixed up in the previous versions
//only one value passed, assume it is the max.
$max = $min;
$min = 0;
}
if($min>$max){
//min is bigger than max, switch.
$x = $max;
$max = $min;
$min = $x;
}
if (($min-$max)==0){
//equal values, return one of them.
return $min;
}
if (!is_array($bell_curve)){
$bell_curve = array(
3 => -0.716599,
4 => -0.708501841,
5 => -0.688258942,
6 => -0.676113203,
7 => -0.659918884,
8 => -0.651821725,
9 => -0.639675985,
10 => -0.631578826,
11 => -0.627530246,
12 => -0.619433087,
13 => -0.611335927,
14 => -0.607287348,
15 => -0.599190188,
16 => -0.595141608,
17 => -0.591093029,
18 => -0.587044449,
19 => -0.582995869,
20 => -0.57894729,
21 => -0.57489871,
22 => -0.57085013,
23 => -0.56680155,
24 => -0.562752971,
25 => -0.558704391,
26 => -0.554655811,
28 => -0.550607232,
29 => -0.546558652,
31 => -0.542510072,
32 => -0.538461492,
34 => -0.534412913,
35 => -0.530364333,
37 => -0.526315753,
39 => -0.522267174,
41 => -0.518218594,
43 => -0.514170014,
45 => -0.510121434,
47 => -0.506072855,
50 => -0.502024275,
52 => -0.497975695,
54 => -0.493927115,
57 => -0.489878536,
60 => -0.485829956,
63 => -0.481781376,
66 => -0.477732797,
69 => -0.473684217,
72 => -0.469635637,
75 => -0.465587057,
79 => -0.461538478,
83 => -0.457489898,
86 => -0.453441318,
90 => -0.449392739,
95 => -0.445344159,
99 => -0.441295579,
104 => -0.437246999,
108 => -0.43319842,
113 => -0.42914984,
118 => -0.42510126,
124 => -0.421052681,
129 => -0.417004101,
135 => -0.412955521,
141 => -0.408906941,
147 => -0.404858362,
154 => -0.400809782,
161 => -0.396761202,
168 => -0.392712623,
175 => -0.388664043,
183 => -0.384615463,
191 => -0.380566883,
199 => -0.376518304,
207 => -0.372469724,
216 => -0.368421144,
226 => -0.364372565,
235 => -0.360323985,
245 => -0.356275405,
256 => -0.352226825,
266 => -0.348178246,
277 => -0.344129666,
289 => -0.340081086,
301 => -0.336032506,
313 => -0.331983927,
326 => -0.327935347,
340 => -0.323886767,
354 => -0.319838188,
368 => -0.315789608,
383 => -0.311741028,
399 => -0.307692448,
415 => -0.303643869,
431 => -0.299595289,
448 => -0.295546709,
466 => -0.29149813,
485 => -0.28744955,
504 => -0.28340097,
523 => -0.27935239,
544 => -0.275303811,
565 => -0.271255231,
587 => -0.267206651,
609 => -0.263158072,
633 => -0.259109492,
657 => -0.255060912,
682 => -0.251012332,
708 => -0.246963753,
734 => -0.242915173,
762 => -0.238866593,
790 => -0.234818014,
820 => -0.230769434,
850 => -0.226720854,
881 => -0.222672274,
914 => -0.218623695,
947 => -0.214575115,
982 => -0.210526535,
1017 => -0.206477955,
1054 => -0.202429376,
1091 => -0.198380796,
1130 => -0.194332216,
1171 => -0.190283637,
1212 => -0.186235057,
1255 => -0.182186477,
1298 => -0.178137897,
1344 => -0.174089318,
1390 => -0.170040738,
1438 => -0.165992158,
1488 => -0.161943579,
1539 => -0.157894999,
1591 => -0.153846419,
1645 => -0.149797839,
1700 => -0.14574926,
1757 => -0.14170068,
1816 => -0.1376521,
1876 => -0.133603521,
1938 => -0.129554941,
2002 => -0.125506361,
2068 => -0.121457781,
2135 => -0.117409202,
2204 => -0.113360622,
2275 => -0.109312042,
2348 => -0.105263463,
2423 => -0.101214883,
2500 => -0.097166303,
2579 => -0.093117723,
2660 => -0.089069144,
2743 => -0.085020564,
2828 => -0.080971984,
2916 => -0.076923405,
3005 => -0.072874825,
3097 => -0.068826245,
3192 => -0.064777665,
3288 => -0.060729086,
3387 => -0.056680506,
3489 => -0.052631926,
3593 => -0.048583346,
3700 => -0.044534767,
3809 => -0.040486187,
3920 => -0.036437607,
4035 => -0.032389028,
4152 => -0.028340448,
4272 => -0.024291868,
4394 => -0.020243288,
4520 => -0.016194709,
4648 => -0.012146129,
4779 => -0.008097549,
4913 => -0.00404897,
5050 => 0, // 5th percentile
5190 => 0.00404819,
5334 => 0.00809677,
5480 => 0.012145349,
5629 => 0.016193929,
5782 => 0.020242509,
5938 => 0.024291088,
6097 => 0.028339668,
6260 => 0.032388248,
6426 => 0.036436828,
6595 => 0.040485407,
6768 => 0.044533987,
6944 => 0.048582567,
7123 => 0.052631146,
7307 => 0.056679726,
7493 => 0.060728306,
7684 => 0.064776886,
7878 => 0.068825465,
8076 => 0.072874045,
8277 => 0.076922625,
8482 => 0.080971205,
8692 => 0.085019784,
8904 => 0.089068364,
9121 => 0.093116944,
9342 => 0.097165523,
9566 => 0.101214103,
9795 => 0.105262683,
10027 => 0.109311263,
10264 => 0.113359842,
10504 => 0.117408422,
10749 => 0.121457002,
10997 => 0.125505581,
11250 => 0.129554161,
11507 => 0.133602741,
11768 => 0.137651321,
12033 => 0.1416999,
12302 => 0.14574848,
12576 => 0.14979706,
12854 => 0.153845639,
13136 => 0.157894219,
13422 => 0.161942799,
13712 => 0.165991379,
14007 => 0.170039958,
14306 => 0.174088538,
14609 => 0.178137118,
14917 => 0.182185697,
15229 => 0.186234277,
15545 => 0.190282857,
15866 => 0.194331437,
16190 => 0.198380016,
16519 => 0.202428596,
16853 => 0.206477176,
17190 => 0.210525755,
17532 => 0.214574335,
17879 => 0.218622915,
18229 => 0.222671495,
18584 => 0.226720074,
18943 => 0.230768654,
19306 => 0.234817234,
19674 => 0.238865814,
20045 => 0.242914393,
20421 => 0.246962973,
20801 => 0.251011553,
21186 => 0.255060132,
21574 => 0.259108712,
21966 => 0.263157292,
22363 => 0.267205872,
22763 => 0.271254451,
23168 => 0.275303031,
23576 => 0.279351611,
23989 => 0.28340019,
24405 => 0.28744877,
24825 => 0.29149735,
25249 => 0.29554593,
25677 => 0.299594509,
26109 => 0.303643089,
26544 => 0.307691669,
26983 => 0.311740248,
27425 => 0.315788828,
27871 => 0.319837408,
28321 => 0.323885988,
28774 => 0.327934567,
29230 => 0.331983147,
29690 => 0.336031727,
30153 => 0.340080306,
30619 => 0.344128886,
31089 => 0.348177466,
31561 => 0.352226046,
32037 => 0.356274625,
32515 => 0.360323205,
32997 => 0.364371785,
33481 => 0.368420365,
33968 => 0.372468944,
34458 => 0.376517524,
34950 => 0.380566104,
35445 => 0.384614683,
35942 => 0.388663263,
36442 => 0.392711843,
36944 => 0.396760423,
37448 => 0.400809002,
37955 => 0.404857582,
38463 => 0.408906162,
38974 => 0.412954741,
39486 => 0.417003321,
40001 => 0.421051901,
40517 => 0.425100481,
41034 => 0.42914906,
41553 => 0.43319764,
42074 => 0.43724622,
42596 => 0.441294799,
43119 => 0.445343379,
43644 => 0.449391959,
44170 => 0.453440539,
44696 => 0.457489118,
45224 => 0.461537698,
45753 => 0.465586278,
46282 => 0.469634857,
46812 => 0.473683437,
47342 => 0.477732017,
47873 => 0.481780597,
48405 => 0.485829176,
48936 => 0.489877756,
49468 => 0.493926336,
50000 => 0.497974916,
50532 => 0.502023495,
51064 => 0.506072075,
51595 => 0.510120655,
52127 => 0.514169234,
52658 => 0.518217814,
53188 => 0.522266394,
53718 => 0.526314974,
54247 => 0.530363553,
54776 => 0.534412133,
55304 => 0.538460713,
55830 => 0.542509292,
56356 => 0.546557872,
56881 => 0.550606452,
57404 => 0.554655032,
57926 => 0.558703611,
58447 => 0.562752191,
58966 => 0.566800771,
59483 => 0.57084935,
59999 => 0.57489793,
60514 => 0.57894651,
61026 => 0.58299509,
61537 => 0.587043669,
62045 => 0.591092249,
62552 => 0.595140829,
63056 => 0.599189408,
63558 => 0.603237988,
64058 => 0.607286568,
64555 => 0.611335148,
65050 => 0.615383727,
65542 => 0.619432307,
66032 => 0.623480887,
66519 => 0.627529466,
67003 => 0.631578046,
67485 => 0.635626626,
67963 => 0.639675206,
68439 => 0.643723785,
68911 => 0.647772365,
69381 => 0.651820945,
69847 => 0.655869525,
70310 => 0.659918104,
70770 => 0.663966684,
71226 => 0.668015264,
71679 => 0.672063843,
72129 => 0.676112423,
72575 => 0.680161003,
73017 => 0.684209583,
73456 => 0.688258162,
73891 => 0.692306742,
74323 => 0.696355322,
74751 => 0.700403901,
75175 => 0.704452481,
75595 => 0.708501061,
76011 => 0.712549641,
76424 => 0.71659822,
76832 => 0.7206468,
77237 => 0.72469538,
77637 => 0.728743959,
78034 => 0.732792539,
78426 => 0.736841119,
78814 => 0.740889699,
79199 => 0.744938278,
79579 => 0.748986858,
79955 => 0.753035438,
80326 => 0.757084017,
80694 => 0.761132597,
81057 => 0.765181177,
81416 => 0.769229757,
81771 => 0.773278336,
82121 => 0.777326916,
82468 => 0.781375496,
82810 => 0.785424076,
83147 => 0.789472655,
83481 => 0.793521235,
83810 => 0.797569815,
84134 => 0.801618394,
84455 => 0.805666974,
84771 => 0.809715554,
85083 => 0.813764134,
85391 => 0.817812713,
85694 => 0.821861293,
85993 => 0.825909873,
86288 => 0.829958452,
86578 => 0.834007032,
86864 => 0.838055612,
87146 => 0.842104192,
87424 => 0.846152771,
87698 => 0.850201351,
87967 => 0.854249931,
88232 => 0.85829851,
88493 => 0.86234709,
88750 => 0.86639567,
89003 => 0.87044425,
89251 => 0.874492829,
89496 => 0.878541409,
89736 => 0.882589989,
89973 => 0.886638568,
90205 => 0.890687148,
90434 => 0.894735728,
90658 => 0.898784308,
90879 => 0.902832887,
91096 => 0.906881467,
91308 => 0.910930047,
91518 => 0.914978626,
91723 => 0.919027206,
91924 => 0.923075786,
92122 => 0.927124366,
92316 => 0.931172945,
92507 => 0.935221525,
92693 => 0.939270105,
92877 => 0.943318685,
93056 => 0.947367264,
93232 => 0.951415844,
93405 => 0.955464424,
93574 => 0.959513003,
93740 => 0.963561583,
93903 => 0.967610163,
94062 => 0.971658743,
94218 => 0.975707322,
94371 => 0.979755902,
94520 => 0.983804482,
94666 => 0.987853061,
94810 => 0.991901641,
94950 => 0.995950221,
95087 => 1, // 95th Percentile
95221 => 1.00404738,
95352 => 1.00809596,
95480 => 1.01214454,
95606 => 1.016193119,
95728 => 1.020241699,
95848 => 1.024290279,
95965 => 1.028338859,
96080 => 1.032387438,
96191 => 1.036436018,
96300 => 1.040484598,
96407 => 1.044533177,
96511 => 1.048581757,
96613 => 1.052630337,
96712 => 1.056678917,
96808 => 1.060727496,
96903 => 1.064776076,
96995 => 1.068824656,
97084 => 1.072873236,
97172 => 1.076921815,
97257 => 1.080970395,
97340 => 1.085018975,
97421 => 1.089067554,
97500 => 1.093116134,
97577 => 1.097164714,
97652 => 1.101213294,
97725 => 1.105261873,
97796 => 1.109310453,
97865 => 1.113359033,
97932 => 1.117407612,
97998 => 1.121456192,
98062 => 1.125504772,
98124 => 1.129553352,
98184 => 1.133601931,
98243 => 1.137650511,
98300 => 1.141699091,
98355 => 1.14574767,
98409 => 1.14979625,
98461 => 1.15384483,
98512 => 1.15789341,
98562 => 1.161941989,
98610 => 1.165990569,
98656 => 1.170039149,
98702 => 1.174087728,
98745 => 1.178136308,
98788 => 1.182184888,
98829 => 1.186233468,
98870 => 1.190282047,
98909 => 1.194330627,
98946 => 1.198379207,
98983 => 1.202427786,
99018 => 1.206476366,
99053 => 1.210524946,
99086 => 1.214573526,
99119 => 1.218622105,
99150 => 1.222670685,
99180 => 1.226719265,
99210 => 1.230767845,
99238 => 1.234816424,
99266 => 1.238865004,
99292 => 1.242913584,
99318 => 1.246962163,
99343 => 1.251010743,
99367 => 1.255059323,
99391 => 1.259107903,
99413 => 1.263156482,
99435 => 1.267205062,
99456 => 1.271253642,
99477 => 1.275302221,
99496 => 1.279350801,
99515 => 1.283399381,
99534 => 1.287447961,
99552 => 1.29149654,
99569 => 1.29554512,
99585 => 1.2995937,
99601 => 1.303642279,
99617 => 1.307690859,
99632 => 1.311739439,
99646 => 1.315788019,
99660 => 1.319836598,
99674 => 1.323885178,
99687 => 1.327933758,
99699 => 1.331982337,
99711 => 1.336030917,
99723 => 1.340079497,
99734 => 1.344128077,
99744 => 1.348176656,
99755 => 1.352225236,
99765 => 1.356273816,
99774 => 1.360322396,
99784 => 1.364370975,
99793 => 1.368419555,
99801 => 1.372468135,
99809 => 1.376516714,
99817 => 1.380565294,
99825 => 1.384613874,
99832 => 1.388662454,
99839 => 1.392711033,
99846 => 1.396759613,
99853 => 1.400808193,
99859 => 1.404856772,
99865 => 1.408905352,
99871 => 1.412953932,
99876 => 1.417002512,
99882 => 1.421051091,
99887 => 1.425099671,
99892 => 1.429148251,
99896 => 1.43319683,
99901 => 1.43724541,
99905 => 1.44129399,
99910 => 1.44534257,
99914 => 1.449391149,
99917 => 1.453439729,
99921 => 1.457488309,
99925 => 1.461536888,
99928 => 1.465585468,
99931 => 1.469634048,
99934 => 1.473682628,
99937 => 1.477731207,
99940 => 1.481779787,
99943 => 1.485828367,
99946 => 1.489876946,
99948 => 1.493925526,
99950 => 1.497974106,
99953 => 1.502022686,
99955 => 1.506071265,
99957 => 1.510119845,
99959 => 1.514168425,
99961 => 1.518217005,
99963 => 1.522265584,
99965 => 1.526314164,
99966 => 1.530362744,
99968 => 1.534411323,
99969 => 1.538459903,
99971 => 1.542508483,
99972 => 1.546557063,
99974 => 1.550605642,
99975 => 1.554654222,
99976 => 1.558702802,
99977 => 1.562751381,
99978 => 1.566799961,
99979 => 1.570848541,
99980 => 1.574897121,
99981 => 1.5789457,
99982 => 1.58299428,
99983 => 1.58704286,
99984 => 1.591091439,
99985 => 1.595140019,
99986 => 1.603237179,
99987 => 1.607285758,
99988 => 1.615382918,
99989 => 1.623480077,
99990 => 1.627528657,
99991 => 1.635625816,
99992 => 1.647771556,
99993 => 1.655868715,
99994 => 1.672063034,
99995 => 1.684208773,
99996 => 1.704451672,
99997 => 1.712548831
);
}
$r = mt_rand(0,100000);
//echo $r." = ";
reset($bell_curve);
while (list($key,$val)=each($bell_curve)){
if ($key>=$r) {
return $min + $val * ($max-$min);
}
}
//We're above 0.99997
return $min + $val * ($max-$min);
//below optomizations don't work atm.
echo $r." = ";
$index="0.00000";
for ($n = 0; $n<strlen($r); $n++){
$f = substr($r,0,$n);
if (isset($bell_curve[(float)$f])) $index = $f;
}
if (strlen($index)>=7){
return $min + $bell_curve[(float)$f] * ($max-$min);
}
$o = strlen($f)-2;
$o = pow(10,$o); // $o is orders of magnitude of our current closest index match
for ($n = 0; $n<10000; $n++){
$x = $n / $o;
if (isset($bell_curve[(float)($f+$x)])) return $min + $bell_curve[(float)($f+$x)] * ($max-$min);
if (isset($bell_curve[(float)($f-$x)])) return $min + $bell_curve[(float)($f-$x)] * ($max-$min);
}
echo "\n<br>Unable to locate random value, \$r was $r<br>\n";
}
?>