-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepeat_mode.py
44 lines (34 loc) · 1.21 KB
/
repeat_mode.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
import random
class AbstractRepeatMode():
def set_repeat_number(self, *args):
raise NotImplementedError()
def get_repeat_number(self):
raise NotImplementedError()
class SimpleRepeatMode(AbstractRepeatMode):
def __init__(self, nb_loops=1):
self.nb_loops = nb_loops
def set_repeat_number(self, *args):
assert(len(args) == 1)
nb_loops = args[0]
assert(isinstance(nb_loops, int))
self.nb_loops = nb_loops
def get_repeat_number(self):
return self.nb_loops
class RandomRepeatMode(AbstractRepeatMode):
def __init__(self, min_repeats, max_repeats, base=1):
self.min_repeats = min_repeats
self.max_repeats = max_repeats
self.base = base
def set_repeat_number(self, *args):
assert(len(args) == 3)
min_repeats = args[0]
max_repeats = args[1]
base = args[2]
assert(isinstance(min_repeats, int))
assert(isinstance(max_repeats, int))
assert(isinstance(base, int))
self.min_repeats = min_repeats
self.max_repeats = max_repeats
self.base = base
def get_repeat_number(self):
return random.randint(self.min_repeats, self.max_repeats)*self.base