jeudi 26 décembre 2019

How do I grab random elements on python from paired lists?

I tried to compare drop height versus rebound height and have some data here:

drop_heights = [0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.7, 2.0]
rebound_heights = [0.16, 0.30, 0.46, 0.6, 0.74, 0.88, 1.02, 1.15, 1.34, 1.51]

I want to select 5 random data points off of these variables, so I tried

smol_drop_heights = []
smol_rebound_heights = []

for each in range(0,5):
     smol_drop_heights.append(drop_heights[randint(0, 9)])
     smol_rebound_heights.append(rebound_heights[randint(0, 9)])
print(smol_drop_heights)
print(smol_rebound_heights)

When they print, they print different sets of data, and sometimes even repeat data, how do I fix this?

[0.8, 1.6, 0.6, 0.2, 0.12]
[1.02, 1.15, 0.88, 0.88, 0.6]

Here is a sample output, where you can see .88 is repeated.




Aucun commentaire:

Enregistrer un commentaire