Skip to content

Commit 96cfbb3

Browse files
committed
Merge branch 'roulette' into maintainer
See LuaJIT#9
2 parents c3224bb + b0a75b4 commit 96cfbb3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bench/roulette.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Russian Roulette simulator
2+
-- This benchmark includes randomness from an external source that can
3+
-- produce non-deterministic performance.
4+
-- See https://github.com/LuaJIT/LuaJIT/issues/218
5+
6+
math.randomseed(os.time())
7+
8+
local population = 100e6
9+
local live = 0
10+
local die = 0
11+
12+
for i = 1, population do
13+
if math.random(6) == 6 then
14+
die = die + 1
15+
else
16+
live = live + 1
17+
end
18+
end
19+
20+
print(("Survived %d/%d (%.3f%%)"):format(live, population, live*100/(live+die)))

0 commit comments

Comments
 (0)