Skip to content

Instantly share code, notes, and snippets.

@superwills
Last active December 28, 2015 16:19
Show Gist options
  • Save superwills/7527655 to your computer and use it in GitHub Desktop.
Save superwills/7527655 to your computer and use it in GitHub Desktop.
Chance table
If you want an event in a game that runs at 60FPS to occur ON AVERAGE (once every 30 seconds),
then the probability interval you should use is 0.000555555556. So pick a range,
say [0, 0.000555555556].
Call randFloat(0,1) once every frame, and if the random generated is on
[0,0.000555555556] then make the event happen.
This table is to choose a probability interval (on [0,1]).
If you want something to occur on average ONCE per second for a 60 FPS game,
then the probability interval for that event should be exactly 1/60 chance
of occurring on each frame (0.016667)
This assumes your probability selector uses a uniformly distributed float on [0,1].
The formula for the # on the right is CHANCE=1/(FPS*avgTime[in units of seconds])
// 0.0166667 per-frame chance means happens once every SECOND on avg
avgTime| CHANCE interval size
0:01 | 0.016666666667
0:02 | 0.008333333333
0:03 | 0.005555555556
0:04 | 0.004166666667
0:05 | 0.003333333333
0:06 | 0.002777777778
0:07 | 0.002380952381
0:08 | 0.002083333333
0:09 | 0.001851851852
0:10 | 0.001666666667
0:11 | 0.001515151515
0:12 | 0.001388888889
0:13 | 0.001282051282
0:14 | 0.001190476190
0:15 | 0.001111111111
0:16 | 0.001041666667
0:17 | 0.000980392157
0:18 | 0.000925925926
0:19 | 0.000877192982
0:20 | 0.000833333333
0:21 | 0.000793650794
0:22 | 0.000757575758
0:23 | 0.000724637681
0:24 | 0.000694444444
0:25 | 0.000666666667
0:26 | 0.000641025641
0:27 | 0.000617283951
0:28 | 0.000595238095
0:29 | 0.000574712644
0:30 | 0.000555555556
0:31 | 0.000537634409
0:32 | 0.000520833333
0:33 | 0.000505050505
0:34 | 0.000490196078
0:35 | 0.000476190476
0:36 | 0.000462962963
0:37 | 0.000450450450
0:38 | 0.000438596491
0:39 | 0.000427350427
0:40 | 0.000416666667
0:41 | 0.000406504065
0:42 | 0.000396825397
0:43 | 0.000387596899
0:44 | 0.000378787879
0:45 | 0.000370370370
0:46 | 0.000362318841
0:47 | 0.000354609929
0:48 | 0.000347222222
0:49 | 0.000340136054
0:50 | 0.000333333333
0:51 | 0.000326797386
0:52 | 0.000320512821
0:53 | 0.000314465409
0:54 | 0.000308641975
0:55 | 0.000303030303
0:56 | 0.000297619048
0:57 | 0.000292397661
0:58 | 0.000287356322
0:59 | 0.000282485876
1:00 | 0.000277777778
1:01 | 0.000273224044
1:02 | 0.000268817204
1:03 | 0.000264550265
1:04 | 0.000260416667
1:05 | 0.000256410256
1:06 | 0.000252525253
1:07 | 0.000248756219
1:08 | 0.000245098039
1:09 | 0.000241545894
1:10 | 0.000238095238
1:11 | 0.000234741784
1:12 | 0.000231481481
1:13 | 0.000228310502
1:14 | 0.000225225225
1:15 | 0.000222222222
1:16 | 0.000219298246
1:17 | 0.000216450216
1:18 | 0.000213675214
1:19 | 0.000210970464
1:20 | 0.000208333333
1:21 | 0.000205761317
1:22 | 0.000203252033
1:23 | 0.000200803213
1:24 | 0.000198412698
1:25 | 0.000196078431
1:26 | 0.000193798450
1:27 | 0.000191570881
1:28 | 0.000189393939
1:29 | 0.000187265918
1:30 | 0.000185185185
1:31 | 0.000183150183
1:32 | 0.000181159420
1:33 | 0.000179211470
1:34 | 0.000177304965
1:35 | 0.000175438596
1:36 | 0.000173611111
1:37 | 0.000171821306
1:38 | 0.000170068027
1:39 | 0.000168350168
1:40 | 0.000166666667
1:41 | 0.000165016502
1:42 | 0.000163398693
1:43 | 0.000161812298
1:44 | 0.000160256410
1:45 | 0.000158730159
1:46 | 0.000157232704
1:47 | 0.000155763240
1:48 | 0.000154320988
1:49 | 0.000152905199
1:50 | 0.000151515152
1:51 | 0.000150150150
1:52 | 0.000148809524
1:53 | 0.000147492625
1:54 | 0.000146198830
1:55 | 0.000144927536
1:56 | 0.000143678161
1:57 | 0.000142450142
1:58 | 0.000141242938
1:59 | 0.000140056022
2:00 | 0.000138888889
2:01 | 0.000137741047
2:02 | 0.000136612022
2:03 | 0.000135501355
2:04 | 0.000134408602
2:05 | 0.000133333333
2:06 | 0.000132275132
2:07 | 0.000131233596
2:08 | 0.000130208333
2:09 | 0.000129198966
2:10 | 0.000128205128
2:11 | 0.000127226463
2:12 | 0.000126262626
2:13 | 0.000125313283
2:14 | 0.000124378109
2:15 | 0.000123456790
2:16 | 0.000122549020
2:17 | 0.000121654501
2:18 | 0.000120772947
2:19 | 0.000119904077
2:20 | 0.000119047619
2:21 | 0.000118203310
2:22 | 0.000117370892
2:23 | 0.000116550117
2:24 | 0.000115740741
2:25 | 0.000114942529
2:26 | 0.000114155251
2:27 | 0.000113378685
2:28 | 0.000112612613
2:29 | 0.000111856823
2:30 | 0.000111111111
2:31 | 0.000110375276
2:32 | 0.000109649123
2:33 | 0.000108932462
2:34 | 0.000108225108
2:35 | 0.000107526882
2:36 | 0.000106837607
2:37 | 0.000106157113
2:38 | 0.000105485232
2:39 | 0.000104821803
2:40 | 0.000104166667
2:41 | 0.000103519669
2:42 | 0.000102880658
2:43 | 0.000102249489
2:44 | 0.000101626016
2:45 | 0.000101010101
2:46 | 0.000100401606
2:47 | 0.000099800399
2:48 | 0.000099206349
2:49 | 0.000098619329
2:50 | 0.000098039216
2:51 | 0.000097465887
2:52 | 0.000096899225
2:53 | 0.000096339114
2:54 | 0.000095785441
2:55 | 0.000095238095
2:56 | 0.000094696970
2:57 | 0.000094161959
2:58 | 0.000093632959
2:59 | 0.000093109870
3:00 | 0.000092592593
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment