forked from swiftlang/swift-experimental-string-processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateDiceNotation.py
67 lines (51 loc) · 1.33 KB
/
generateDiceNotation.py
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
import string
import random
random.seed(0)
minDigits = 1
maxDigits = 4
def number():
return "".join([random.choice(string.digits) for _ in range(random.randint(minDigits,maxDigits))])
minWord = 5
maxWord = 10
def word():
return "".join([random.choice(string.ascii_letters) for _ in range(random.randint(minWord,maxWord))])
minDice = 1
maxDice = 4
def roll():
die = []
for _ in range(random.randint(minDice, maxDice)):
roll = ""
if random.randint(0,1) == 1:
roll += number()
if random.randint(0,1) == 1:
roll += "d" + number()
else:
roll += "D" + number()
die.append(roll)
return "+".join(die)
line_num = 2000
things_per_line = 10
lines = []
for _ in range(line_num):
line = []
for _ in range(things_per_line):
if random.randint(0,1) == 1:
line.append(word())
else:
line.append(roll())
lines.append(" ".join(line))
dice_text = "\n ".join(lines)
dice_rolls = []
for _ in range(2000):
dice_rolls.append(roll())
dice_rolls_formatted = "[" + ",\n ".join(["\"" + x + "\"" for x in dice_rolls]) + "]"
res = """
extension Inputs {{
/// Generated by Utils/benchmark-generators/generateDiceNotation.py
static let diceRollsInText: String = \"\"\"
{0}
\"\"\"
static let diceRolls: [String] = {1}
}}
"""
print(res.format(dice_text, dice_rolls_formatted))