dimanche 31 juillet 2022

random.randint is not picking "random" numbers [closed]

I'm trying to generate 4 lists with random numbers. But the numbers don't seem "random" at all. They are very similar to one another, which is very frustrating. Here is my function:

def generate_Lt_Ut(n, delta):
    Ut1 = [random.randint(1,100) for i in range(n)]
    Ut2 = [random.randint(1,100) for i in range(n)]
    Lt1 = [random.randint(max(1,Ut1[i]-delta),Ut1[i]) for i in range(n)]
    Lt2 = [random.randint(max(1,Ut2[i]-delta),Ut2[i]) for i in range(n)]
    return Ut1, Ut2, Lt1, Lt2

I tried running the following a couple of times:

Ut1, Ut2, Lt1, Lt2 = generate_Lt_Ut(4, 30)
print("Ut1: " + str(Ut1))
print("Ut2: " + str(Ut2))
print("Lt1: " + str(Lt1))
print("Lt2: " + str(Lt2))

Here is what I got:

Repetition 1:

Ut1: [91, 91, 91, 91]
Ut2: [91, 91, 91, 91]
Lt1: [72, 72, 72, 72]
Lt2: [72, 72, 72, 72]

Reptetition 2:

Ut1: [79, 79, 79, 79]
Ut2: [79, 79, 79, 79]
Lt1: [77, 77, 77, 77]
Lt2: [77, 77, 77, 77]

Repetition 3:

Ut1: [99, 99, 99, 99]
Ut2: [99, 99, 99, 99]
Lt1: [72, 72, 72, 72]
Lt2: [72, 72, 72, 72]

Repetition 4:

Ut1: [89, 89, 89, 89]
Ut2: [89, 89, 89, 89]
Lt1: [74, 74, 74, 74]
Lt2: [74, 74, 74, 74]

I have no idea what's going on and would appreciate any help.




Aucun commentaire:

Enregistrer un commentaire