Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Nov 20, 2020. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.lua
More file actions
Latest commit
74 lines (63 loc) · 1.21 KB
/
Copy pathtest.lua
File metadata and controls
74 lines (63 loc) · 1.21 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
-- test random library
require"random"
print(random.version)
print""
functiontest(w,r)
print(w,r(),r(),r())
end
r=random.new(12345)
test("new",r)
test("more",r)
test("reset",r:seed(12345))
test("seed",r:seed(56789))
test("seed",r:seed(3063121584))
test("seed",r:seed(2428144928))
s=r:seed():clone()
test("seed",r)
test("more",r)
test("clone",s)
r:seed(os.time())
N=100000
print""
print("range","","distribution",N)
print("","",1,2,3,4,5,6,7,8)
functiontest(N,a,b)
localS={0,0,0,0,0,0,0,0,0,0,0}
fori=1,Ndo
locali=r:value(a,b)
ifi~=nilthenS[i]=S[i]+1end
end
fori=1,9do
S[i]=math.floor(100*S[i]/N+0.5)
end
print(a..":"..b,"",S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[8])
end
test(N,1,8)
test(N,2,4)
test(N,3,7)
test(N,7,3)
test(N,1.2,4.6)
test(N,4.6,1.2)
test(N,7.1,2.9)
test(N,2.9,7.1)
test(N,2.1,2.2)
test(N,2.2,2.1)
functiontest(w,f)
localt=os.clock()
fori=1,Ndo
f()
end
t=os.clock()-t
print(w,math.floor(N/t/1000),N,t)
end
N=4*N
print""
print("","1000/s","N","time")
test("math",function () returnmath.random() end)
test("math",math.random)
test("random",function () returnrandom.value(r) end)
test("random",function () returnr:value() end)
test("random",r)
print""
print(random.version)
-- eof