-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.py
207 lines (190 loc) · 7 KB
/
generator.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import random
from math import pi, log10, ceil
from preferences import*
class SetGen:
def __init__(self):
self.R = React()
self.array = []
self.menu = {
'all': 'choose all',
'man': 'manual',
'non': 'none',
'nrm': 'normal',
'vms': 'vonmises',
'wbl': 'weibull',
'prt': 'pareto',
'bta': 'beta',
'gma': 'gamma',
'tri': 'triangular',
'exp': 'exponential',
'lgn': 'lognormal',
'ex': 'exit',
}
self.menuNonUsable = (
'all',
'man',
'ex',
)
self.modesMenu = {
'a': 'auto',
'm': 'manual',
}
def giveArray(self):
return self.array
def manual(self, start, stop, quantity):
try:
section = 'MANUAL MODE'
print(f'\t\t\t{self.R.splitL} {section} {self.R.splitR}')
self.array = []
text = '\t\t\tpass number of elements: '
quantity = int(input(text))
i = 0
for i in range(quantity):
text = f'\t\t\tpass {i + 1} value: '
while True:
try:
value = int(input(text))
self.array.append(value)
break
except:
self.R.printIncorrectItem('value')
i += 1
except Exception as e:
self.R.printException('manual distribution', e)
def none(self, start, stop, quantity):
try:
self.array = []
rang = stop - start
gap = rang / quantity
gap = int(ceil(gap))
while len(self.array) < quantity:
value = start
for i in range(quantity):
pool = random.randint(0, 2 * gap)
value += pool
if value > stop or len(self.array) >= quantity:
break
ind = random.randint(0, i)
self.array.insert(ind, value)
except Exception as e:
self.R.printException('none distribution', e)
def normal(self, start, stop, quantity):
try:
self.array = []
mu = random.randint(start, stop)
sigma = random.randint(1, 50)
for _ in range(quantity):
number = int(random.gauss(mu, sigma))
number = max(start, min(stop, number))
self.array.append(number)
except Exception as e:
self.R.printException('normal distribution', e)
def triangular(self, start, stop, quantity):
try:
self.array = []
modeParam = random.randint(start, stop)
for _ in range(quantity):
args = (start, stop, modeParam)
number = random.triangular(*args)
number = int(number)
self.array.append(number)
except Exception as e:
self.R.printException('triangular distribution', e)
def beta(self, start, stop, quantity):
try:
self.array = []
values = (0, 10)
alpha = random.triangular(0, 10, random.choice(values))
beta = random.triangular(0, 10, random.choice(values))
args = (alpha, beta)
rang = log10(stop)*10
for _ in range(quantity):
dist = random.betavariate(*args)
number = int(start + dist * rang)
self.array.append(number)
except Exception as e:
self.R.printException('beta distribution', e)
def exponential(self, start, stop, quantity):
try:
self.array = []
lambd = random.triangular(5, 10, 10)
sel = random.choice((-1, 1))
lambd *= sel
rang = log10(stop)*10
for _ in range(quantity):
dist = random.expovariate(lambd)
if abs(lambd) != lambd:
number = int(stop + dist * rang)
else:
number = int(start + dist * rang)
self.array.append(number)
except Exception as e:
self.R.printException('exponential distribution', e)
def gamma(self, start, stop, quantity):
try:
self.array = []
values = (0, 10)
alpha = random.triangular(0, 10, random.choice(values))
beta = random.triangular(0, 10, random.choice(values))
args = (alpha, beta)
rang = log10(stop)*10
for _ in range(quantity):
dist = random.gammavariate(*args)
number = int(start + dist * rang)
self.array.append(number)
except Exception as e:
self.R.printException('gamma distribution', e)
def lognormal(self, start, stop, quantity):
try:
self.array = []
mu = random.randint(1, 10)
sigma = 1
args = (mu, sigma)
for _ in range(quantity):
dist = random.lognormvariate(*args)
number = int(start + dist)
self.array.append(number)
except Exception as e:
self.R.printException('log normal distribution', e)
def vonmises(self, start, stop, quantity):
try:
self.array = []
mu = random.triangular(0, pi, 0)
kappa = abs(random.uniform(start, stop))
args = (mu, kappa)
rang = log10(stop)*10
for _ in range(quantity):
dist = random.vonmisesvariate(*args)
number = int(start + dist * rang)
self.array.append(number)
except Exception as e:
self.R.printException('von mises distribution', e)
def pareto(self, start, stop, quantity):
try:
self.array = []
upper = 10**int(log10(stop) - 1)
sel = random.choice((-10, 0, 0, 10))
alpha = random.triangular(-10, 10, sel)
for _ in range(quantity):
dist = random.paretovariate(alpha)
if sel >= 0:
number = int(start + dist * upper)
else:
number = int(start + dist * upper)
self.array.append(number)
except Exception as e:
self.R.printException('pareto distribution', e)
def weibull(self, start, stop, quantity):
try:
self.array = []
upper = 10**int(log10(stop))
sel = random.choice((-10, 0, 0, 10))
alpha = random.uniform(1, upper)
beta = random.triangular(-10, 10, sel)
args = (alpha, beta)
for _ in range(quantity):
dist = random.weibullvariate(*args)
number = int(start + dist)
self.array.append(number)
except Exception as e:
self.R.printException('weibull distribution', e)