+2 votes
in Programming Languages by (73.8k points)
How to generate a list of random values that are between 0 and 1 (probabilities) in Python?

1 Answer

+1 vote
by (348k points)
selected by
 
Best answer

You can use the random() function of the random module of Python. It returns a random floating-point number in the range [0.0, 1.0). To generate a list of such numbers, use the random() function as follows:

This code generates 10 probabilities.

>>> [random.random() for i in range(10)]
[0.994111215306974, 0.36516543742601426, 0.9468046451430949, 0.1658592132198271, 0.4400915815926201, 0.659780469893188, 0.14083260642547446, 0.6450180011232027, 0.7898507834159088, 0.9500984405471881]


...