-
Notifications
You must be signed in to change notification settings - Fork 2
/
randFloats.py
107 lines (92 loc) · 3.17 KB
/
randFloats.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
import random as r
import string
""" Author @Javi801
Gives an array with "cantidad" of random floats, between Tmin and Tmax, using
a given seed for randomize numbers. It will gives one number per (Tmax/cantidad).
Param: Seed -> (float) seed for randomize
Tmin -> (float) minimun number
Tmax -> (float) maximal number
cantidad -> (int) total of number required
Return: an array of float numbers
"""
def gen(Seed, Tmin, Tmax, cantidad):
Tmin=Tmin*1.0
Tmax=Tmax*1.0
r.seed(Seed)
inter=intervalo(Tmin, Tmax, cantidad)
intervaloInicial=Tmin
intervaloFinal=inter+Tmin
final=[]
for i in range(cantidad):
num=r.uniform(intervaloInicial,intervaloFinal)
final+=[num]
intervaloInicial+=inter
intervaloFinal+=inter
return final
""" Author @Javi801
Calcule the interval between Tmin and Tmax, consider "cantidad" of intervals
Param: Tmin -> (float) minimun number
Tmax -> (float) maximal number
cantidad -> (int) total of number required
Return: inter -> (float) interval calculated
"""
def intervalo(Tmin, Tmax, cantidad):
Tmin=Tmin*1.0
Tmax=Tmax*1.0
inter=(Tmax-Tmin)/cantidad
return inter
"""
Gives an array with "cantidad" of floats per second between Tmin and Tmax.
Param: Seed -> (float) seed for randomize
tmin -> (float) minimum number
tmax -> (float) maximal number
cantidad -> (int) number of queries per second
Note: tmax - tmin must be equals or greater than 1
"""
def genInter(Seed, tmin, tmax, cantidad):
inter = []
t0 = tmin
t1 = tmin + 1
for i in range(int(tmax - tmin)):
sub_i = gen(Seed, t0, t1, cantidad)
inter.extend(sub_i)
t0 += 1
t1 += 1
return inter
""" @Javi801
Gives an array with letters or letter plus numbers, with the length given. The
content can be random if you enter the parameter aleatorio=1.
Param: aleatorio -> (boolean) True if the content must be random, false if not
contador -> (int) index where start to cut letters and numbers to add at
final array
largo -> (int) length of the array
solo_letras -> (boolean) True if the content must be only letter, false
if it can be numbers as well
Seed -> (float) seed for randomize
Return: inter -> (float) interval calculated
"""
def randomString(aleatorio, contador, largo, solo_letras, Seed):
r.seed(Seed)
letras=string.ascii_letters
todo=string.ascii_letters+string.digits
if aleatorio and solo_letras:
return ''.join(r.choice(letras) for i in range(largo))
if aleatorio:
return ''.join(r.choice(todo) for i in range(largo))
if solo_letras:
contador=contador%len(letras)
final=letras[contador:]
if len(final)<largo:
m=int((largo-len(final))/len(letras))
final+=(letras*m)
final+=letras[:largo-len(final)]
final=final[:largo]
return final
contador=contador%len(todo)
final=todo[contador:]
if len(final)<largo:
m=int((largo-len(final))/len(todo))
final+=(todo*m)
final+=todo[:largo-len(final)]
final=final[:largo]
return final