I've read the manual for pseudo-randomness in Python, and to my knowledge, you can only generate numbers up to a given maximum value, i.e. 0-1, 0-30, 0-1000, etc. I want to:
I've looked around, and I can't find anywhere that explains this.
To create a list of random numbers without duplicates with Python, we can use the random. sample method. We call random. sample with the range of numbers to generate and the number of random numbers to generate respectively.
difference between random () and randint()The random command will generate a rondom value present in a given list/dictionary. And randint command will generate a random integer value from the given list/dictionary.
Create an integer random between e.g. 1-11
and multiply it by 5
. Simple math.
import random for x in range(20): print random.randint(1,11)*5, print
produces e.g.
5 40 50 55 5 15 40 45 15 20 25 40 15 50 25 40 20 15 50 10
>>> import random >>> random.randrange(5,60,5)
should work in any Python >= 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With