This repository has been archived by the owner on Sep 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroll
executable file
·70 lines (66 loc) · 1.52 KB
/
roll
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
#!/usr/bin/env lua
local args={...}
local n=args[1]
local m=args[2]
math.randomseed(os.time())
local errored=false
if n=='choice' then
local choices={}
for l in io.lines() do
table.insert(choices, l)
end
io.write(choices[math.random(#choices)])
elseif n=='magic' then
local choices={
"As I see it, yes",
"Don't count on it",
"Yes",
"Outlook good",
"Concentrate and ask again",
"Yes, definitely",
"Signs point to yes",
"It is decidedly so",
"Ask again later",
"Most likely",
"Outlook not so good",
"My sources say no",
"Better not tell you now",
"You may rely on it",
"Without a doubt",
"Very doubtful",
"Cannot predict now",
"Reply hazy try again",
"It is certain",
"My reply is no"
}
io.write(choices[math.random(#choices)])
io.write '\n'
elseif tonumber(n) then
n=tonumber(n)
m=tonumber(m)
if m then
if m<n then
m, n=n, m
end
io.write(math.random(n, m))
else
if n==0 then
errored=true
else
io.write(math.random(n))
end
end
else
errored=true
end
if errored then
io.stderr:write "Usage:\n"
io.stderr:write "\troll <n>\n"
io.stderr:write "\t\tRolls a pseudorandom integer between 1 and n inclusive\n"
io.stderr:write "\troll <n> <m>\n"
io.stderr:write "\t\tRolls a pseudorandom integer between n and m (which don't have to be in order), inclusive\n"
io.stderr:write "\troll choice\n"
io.stderr:write "\t\tReturns a random line from stdin, without the trailing eol\n"
io.stderr:write "\troll magic\n"
io.stderr:write "\t\tRolls a magic 20 (aka magic 8 pool)\n"
end