Random

We can create random numbers in Python in a number of ways.

If we want a range of number between 0 and another number e.g. 10 we can use randrange

from random import randrange
print randrange(10)

We can also use randint(x,y) to get a random int between x and y.

from random import randint
print randint(5,10)

We can also make a random choice from a given list e.g.

rooms = ["Kitchen", "Conservatory", "Lounge", "Dining Room", "Bedroom", "Library"] 
room = choice(rooms)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.