{"id":516,"date":"2020-10-14T17:28:45","date_gmt":"2020-10-14T17:28:45","guid":{"rendered":"https:\/\/marshallbrain.com\/wordpress\/?page_id=516"},"modified":"2020-10-14T17:28:45","modified_gmt":"2020-10-14T17:28:45","slug":"python3","status":"publish","type":"page","link":"https:\/\/marshallbrain.com\/python3","title":{"rendered":"Marshall Brain\u2019s Quick and Easy Python Tutorials \u2013 Chapter 3"},"content":{"rendered":"\n

by Marshall Brain<\/a><\/p>\n\n\n\n

Let’s say someone asks you to do an experiement: You are to flip a coin 1,000 times and record how many heads and tails you actually get.<\/p>\n\n\n\n

It’s a simple experiment, and anyone could do it. But who has time for that? Who wants to stand there flipping a coin 1,000 times and recording the results on a piece of paper? It could take an hour. If they asked you to flip the coin 10,000 times, it would take all day.<\/p>\n\n\n\n

This is a perfect place to use a computer simulation. A little computer program can flip a coin 1,000 times in less than a second and tell you the result.<\/p>\n\n\n\n

How to do it? The first thing we need to learn about is something called a\u00a0random number generator<\/em>. This is a piece of code that generates a random number for us. Here is a tiny little program that shows you how one of Python’s random number generators works:<\/p>\n\n\n\n