blob: d732386e3c2a389cbb0696ebbd2a11603c0dfb37 (
plain)
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
|
rng = {}
totally_random_seed = tonumber(os.date("%Y%H%M%S"))
math.randomseed(totally_random_seed)
rng.generator = (seed, m, n) ->
seed = seed or tonumber(os.date("%Y%S"))
co = coroutine.wrap(() ->
while true
math.randomseed(seed)
seed = math.random(m,n)
coroutine.yield(seed)
)
co, seed
rng.randomstring = (charset, length) ->
t = {}
charset_len = #charset
for i = 1, length
char = math.random(charset_len)
t[i] = charset\sub(char,char)
table.concat(t)
rng.hexstring = (length) ->
rng.randomstring("0123456789ABCDEF", length)
rng.numstring = (length) ->
rng.randomstring("0123456789", length)
rng
|