The standard way to generate a random number is to use the random (opens new window) module. The
random() function will return a floating point number from 0 to 1 (but not including 1). In addition, there's also a
choice() function that will randomly select an item from a list.
choice() can be used to select from a pre-specified list of characters or numbers.
Here's an example of how to generate a random number using
And here's an example of how to use
choice() to generate a random string: