CodeNewbie Community 🌱

Discussion on: How can I generate random numbers in Python?

Collapse
 
rickmeasham profile image
Rick Measham

@swizzard and @yechielk are right on here.

randint() will return a number integer between range_min and range_max inclusive. So if you call randint(1,10) you will get a random integer equal to 1, 2, 3, ..., 9, 10.

The random library has a number of useful functions in it for dealing with random things. For example if you need a random element from a list, use choice():

suit = choice(['hearts', 'diamonds', 'spades', 'clubs'])
Enter fullscreen mode Exit fullscreen mode

Documentation is here: docs.python.org/3/library/random.html