import random
Returns a random integer between x
and y
(inclusive):
random.randint(x, y)
For example getting a random number between 1
and 8
:
random.randint(1, 8) # Out: 8
random.randrange
has the same syntax as range
and unlike random.randint
, the last value is not inclusive:
random.randrange(100) # Random integer between 0 and 99
random.randrange(20, 50) # Random integer between 20 and 49
random.rangrange(10, 20, 3) # Random integer between 10 and 19 with step 3 (10, 13, 16 and 19)
Returns a random floating point number between 0 and 1:
random.random() # Out: 0.66486093215306317
Returns a random floating point number between x
and y
(inclusive):
random.uniform(1, 8) # Out: 3.726062641730108