06.0 Python‎ > ‎Python Notes‎ > ‎

Python: Random Numbers

For more information on the random class, see the Python Standard Library Docs

Sample Code

import random 
# if .seed is used random will create the identical random numbers for the same seed value 
random.seed(12) 
 
 
# .randint creates random integers within the given range 
print("Random Integers") 
for x in range(0,10): 
    rNumber = random.randint(1,100) 
    print (rNumber) 
 
# .random creates random float in the range [0,1) 
print("Random Floats") 
for x in range (0,10): 
    rNumber = random.random() 
    print(rNumber)
Comments