creating list of random numbers in python

Viewed 284

I have initiated a list of known length with zeros. I am trying to go back through the list and put random floating point numbers from 0-1 at each index. I am using a while loop to do this. However, the code is not putting the random numbers in. The list is still full of zeros and I do not understand why. I've inserted a print statement which is telling me the list is still full of zeros. I would appreciate any help!

randomList = [0]*10
index = 0
while index < 10:
    randomList[index] = random.random()
    print("%d" %randomList[index])
    index = index + 1
4 Answers
Related