mardi 15 septembre 2020

How to create an array that is filled with elements randomly selected from another array [duplicate]

Basically say i have this array d = [1,6,7,4,9] and i want to take that content randomly and fill it into another array using a for loop a certain number of times and print the result so,

d= [1,6,7,4,9]

n = 100

s = []

for i in range(n)

   s[i] = random.choice(d)

print(s)

however, I'm getting the error that list assignment is out of range and just wanted to know what would be the best way to get this code to run. My main problem is appending the random choice into the new array.




Aucun commentaire:

Enregistrer un commentaire