homework 4 example bernard chen 2007. how do we generate random number in python random is a very...
TRANSCRIPT
![Page 1: Homework 4 Example Bernard Chen 2007. How do we generate Random number in Python Random is a very important method in math and statistics, how could we](https://reader035.vdocuments.net/reader035/viewer/2022072010/56649dcf5503460f94ac3217/html5/thumbnails/1.jpg)
Homework 4 Example
Bernard Chen 2007
![Page 2: Homework 4 Example Bernard Chen 2007. How do we generate Random number in Python Random is a very important method in math and statistics, how could we](https://reader035.vdocuments.net/reader035/viewer/2022072010/56649dcf5503460f94ac3217/html5/thumbnails/2.jpg)
How do we generate Random number in Python Random is a very important method in
math and statistics, how could we generate random number in Python?
We have a build-in model called Random
If we want to use it, we need to “import” the model first
>>> import random
![Page 3: Homework 4 Example Bernard Chen 2007. How do we generate Random number in Python Random is a very important method in math and statistics, how could we](https://reader035.vdocuments.net/reader035/viewer/2022072010/56649dcf5503460f94ac3217/html5/thumbnails/3.jpg)
Random Function Random model has many different
functions to generate random numbers
I introduce random.choice(<ordered object>) here
In this function, it will randomly choice a object from the given ordered object
![Page 4: Homework 4 Example Bernard Chen 2007. How do we generate Random number in Python Random is a very important method in math and statistics, how could we](https://reader035.vdocuments.net/reader035/viewer/2022072010/56649dcf5503460f94ac3217/html5/thumbnails/4.jpg)
Random Function Example
random.choice([1,2,3,4,5]) (ordered object)
random.choice(‘asdfghjkl;’) random.choice(range(1000))
![Page 5: Homework 4 Example Bernard Chen 2007. How do we generate Random number in Python Random is a very important method in math and statistics, how could we](https://reader035.vdocuments.net/reader035/viewer/2022072010/56649dcf5503460f94ac3217/html5/thumbnails/5.jpg)
References
http://docs.python.org/lib/module-random.html
![Page 6: Homework 4 Example Bernard Chen 2007. How do we generate Random number in Python Random is a very important method in math and statistics, how could we](https://reader035.vdocuments.net/reader035/viewer/2022072010/56649dcf5503460f94ac3217/html5/thumbnails/6.jpg)
Demo
Try to come up with an interesting example to use it.