- Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdemo.lua
More file actions
Latest commit
42 lines (38 loc) · 1.27 KB
/
Copy pathdemo.lua
File metadata and controls
42 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require('randomlua')
l1=lcg(0) -- Linear congruential generator (Ansi C params)
l2=lcg(0, 'nr') --Linear congruential generator (Numerical recipes params)
c1=mwc(0) -- Multiply-with-carry (Ansi C params)
c2=mwc(0, 'nr') -- Multiply-with-carry (Numerical recipes params)
m=twister(0) -- Mersenne twister
forn=1, 10do
io.write(string.format("%8u%8u%8u%8u%16u\n", l1:random(0), l2:random(0), c1:random(0), c2:random(0), m:random(0)))
end
-- lets run them all a bunch of times and gather stats
count=10000
names= {"l1", "l2", "c1", "c2", "m"}
generators= {l1, l2, c1, c2, m}
mins= {}
maxs= {}
bins= {}
fori, geninipairs(generators) do
bins[i] = {}
forn=1, countdo
x=gen:random()
bin=math.floor(x*10) +1
bins[i][bin] = (bins[i][bin] or0) +100/count
ifmins[i] ==nilorx<mins[i] then
mins[i] =x
end
ifmaxs[i] ==nilorx>maxs[i] then
maxs[i] =x
end
end
end
print("name: min - max [histogram of each 10%]")
fori=1, #generatorsdo
forj=1, #bins[i] do
bins[i][j] =string.format("%2.0f%%", bins[i][j])
end
distribution=table.concat(bins[i], "")
print(string.format("%2s: %f - %f [%s]", names[i], mins[i], maxs[i], distribution))
end