Skip to content

Commit 988f08e

Browse files
committed
Generazione di lista di numeri casuali
1 parent 1979805 commit 988f08e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/pairslist.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
"""
77

88
from pairslist_impl import Head, Tail, EmptyList, MakeList
9+
from random import seed, randint
10+
11+
# Inizializza il generatore di numeri casuali
12+
# Vedi la documentazione del modulo random:
13+
# https://docs.python.org/3/library/random.html
14+
seed(13)
15+
def MakeRandomInts(n, a, b):
16+
""" Restituisce una lista n di numeri causali, uniformente distribuiti
17+
nell'intervallo [a,b] (estremi compresi) """
18+
if n == 0:
19+
return EmptyList()
20+
return MakeList(randint(a,b), MakeRandomInts(n-1, a, b))
921

1022

1123
def PrintList(As):
@@ -103,10 +115,13 @@ def ReverseI(Ls, Rs):
103115
#-----------------------------------------------
104116
if __name__ == "__main__":
105117
Ls = MakeRange(1, 5)
106-
107118
print("MakeList(7): ", end='')
108119
PrintList(Ls)
109120

121+
Rs = MakeRandomInts(10, 1, 100)
122+
print("MakeRandomInts(10, 1, 100): ", end='')
123+
PrintList(Rs)
124+
110125
Cs = MakeRange(3,7)
111126
print("MakeRange(3,7): ", end='')
112127
PrintList(Cs)

0 commit comments

Comments
 (0)