-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometric_distribution.py
More file actions
executable file
·102 lines (81 loc) · 4.36 KB
/
geometric_distribution.py
File metadata and controls
executable file
·102 lines (81 loc) · 4.36 KB
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
#!/usr/bin/python3
from random import uniform
from math import pow
from pprint import pprint
print("""
'########::'####::'######::'########:'########::'####:'########::'##::::'##::'######::'####::'#######::'##::: ##:
##.... ##:. ##::'##... ##:... ##..:: ##.... ##:. ##:: ##.... ##: ##:::: ##:'##... ##:. ##::'##.... ##: ###:: ##:
##:::: ##:: ##:: ##:::..::::: ##:::: ##:::: ##:: ##:: ##:::: ##: ##:::: ##: ##:::..::: ##:: ##:::: ##: ####: ##:
##:::: ##:: ##::. ######::::: ##:::: ########::: ##:: ########:: ##:::: ##: ##:::::::: ##:: ##:::: ##: ## ## ##:
##:::: ##:: ##:::..... ##:::: ##:::: ##.. ##:::: ##:: ##.... ##: ##:::: ##: ##:::::::: ##:: ##:::: ##: ##. ####:
##:::: ##:: ##::'##::: ##:::: ##:::: ##::. ##::: ##:: ##:::: ##: ##:::: ##: ##::: ##:: ##:: ##:::: ##: ##:. ###:
########::'####:. ######::::: ##:::: ##:::. ##:'####: ########::. #######::. ######::'####:. #######:: ##::. ##:
........:::....:::......::::::..:::::..:::::..::....::........::::.......::::......:::....:::.......:::..::::..::
:'######:::'########::'#######::'##::::'##:'########:'########:'########::'####::'######:::::'###::::
'##... ##:: ##.....::'##.... ##: ###::'###: ##.....::... ##..:: ##.... ##:. ##::'##... ##:::'## ##:::
##:::..::: ##::::::: ##:::: ##: ####'####: ##:::::::::: ##:::: ##:::: ##:: ##:: ##:::..:::'##:. ##::
##::'####: ######::: ##:::: ##: ## ### ##: ######:::::: ##:::: ########::: ##:: ##:::::::'##:::. ##:
##::: ##:: ##...:::: ##:::: ##: ##. #: ##: ##...::::::: ##:::: ##.. ##:::: ##:: ##::::::: #########:
##::: ##:: ##::::::: ##:::: ##: ##:.:: ##: ##:::::::::: ##:::: ##::. ##::: ##:: ##::: ##: ##.... ##:
. ######::: ########:. #######:: ##:::: ##: ########:::: ##:::: ##:::. ##:'####:. ######:: ##:::: ##:
:......::::........:::.......:::..:::::..::........:::::..:::::..:::::..::....:::......:::..:::::..:
[...] Owner: Arturo Negreiros Samanez [...]
[...] date: 09/07/2021 [...]
[...] follow me: https://twitter.com/DevTuron [...]
[...] source code: https://github.com/Arturo0911/Simulation [...]
""")
def geometric_form(pr: float, i_counter: int) -> float:
return float(1 - pow((1 - pr),i_counter))
def all_values(k_values: int, pr: float) -> list:
return [geometric_form(pr, i) for i in range(1, k_values+1)]
def making_values_geometrict(k_values: int, pr: float) -> int:
uniform_val = uniform(0,1)
print("[*] Estos son los %s valores generados \n"%k_values)
for i, j in enumerate(all_values(k_values, pr)):
print("%s : %s"%(i+1,j))
print("\n\n")
print("[*] El valor aleatorio generados es: %s"%uniform_val)
x_value = None
counter = 1
for x in range(1, len(all_values(k_values, pr))+1):
if uniform_val < all_values(k_values, pr)[counter-1]:
x_value = counter
break
else:
counter += 1
print("[*] el valor de x corresponde a la posicion : %s que es menor que el valor %s"%(x_value,all_values(k_values, pr)[x_value-1]))
def main():
while True:
try:
print("[*] Distribucion geométrica")
while True:
k_val = int(input("[*] ingresa la cantidad de valores que debe tener k: "))
if k_val < 1000:
break
else:
print("[x] El valor de k no debe ser mayor a 1000")
while True:
pr_val = float(input("[*] Ingrese el valor de pr: "))
if pr_val < 1:
break
else:
print("[x] El valor de pr debe ser un valor probabilístico, o sea entre 0 y 1")
making_values_geometrict(k_val, pr_val)
except KeyboardInterrupt:
print("[*] Saliendo...")
except Exception:
print("[*] Saliendo")
print("[*] ¿Deseas hacer otra prueba? ")
try:
test = input("inserte opction S/N> ")
test = test.lower()
if test != "s":
print("[*] Saliendo...")
break
else:
continue
except:
print("[x] Opcion incorrecta")
print("[*] Saliendo...")
if __name__ == "__main__":
main()