CS 022A Lecture 11: CS22A #10: Random Number Generation
Document Summary
Random number generation keep games interesting also used in simulation and security. To generate random numbers in python we need to load python module random. Modules are libraries that contain a collection of specialized functions. To use a module we have to explicitly load it to the program using the import statement. Once the random module is loaded we can use the functions included. We can select random element from given list. Choice() is used for choosing an element from a sequence at random. A different element is returned everytime choice() is called. The function random() returns a random float between 0. 0 and 1. 0. Each time random() is called, it generates floating-point values between 0 and 1. For i in range(10) # generate 10 random nums. Random module - randint() function randint() generate integer numbers in specified range. Takes two parameters and returns an integer in the range between the two.