CMPT 120 Lecture Notes - Lecture 21: Stochastic Process
meghan78 and 39786 others unlocked
29
CMPT 120 Full Course Notes
Verified Note
29 documents
Document Summary
Python includes a module called random for working with random numbers. The random module includes various functions to generate random numbers. randint() randrange() random() uniform() Import the random module to use (call) the random functions. Use of module requires an import random statement. Format: module_name. function_name() random. randint() r andom. randint(1, 10) number = random. randint(1, 10) Random number functions randint(): generates a random number in the range provided by the arguments. randrange: similar to range function, but returns randomly selected integer from the specified range: random. randrange(10) random. randrange(11, 30) For example: 155 random function: it returns a random float in the range of 0. 0 and 1. 0 the random function does not receive any arguments. uniform function: returns a random float but allows user to specify range. Random number functions use clock time as a seed value. We can specify our own seed value. random. seed() random. seed(10) Same seed value generate a same set of random numbers.