Random Numbers In today’s lesson we will look at:

Slides:



Advertisements
Similar presentations
Random Numbers In today’s lesson we will look at: why we might want a random number whether they really are random how to create and scale random numbers.
Advertisements

Chapter 11: understanding randomness (Simulations)
Copyright © 2010 Pearson Education, Inc. Unit 3: Gathering Data Chapter 11 Understanding Randomness.
Art 315 Lecture 6 Dr. J. Parker. Variables Variables are one of a few key concepts in programming that must be understood. Many engineering/cs students.
Probability Refresher COMP5416 Advanced Network Technologies.
Randomness Exploring Computer Science Lesson 4-10 – Part 2.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own.
SETS AND VENN DIAGRAMS.
The Monster Song.
11.1: Tests for Goodness of Fit
Days of the Week Rap Back
Days of the week NEXT.
Days of the Week Les docs d’Estelle –
Random numbers Taken from notes by Dr. Neil Moore
DAYS OF THE WEEK.
Chapter 11 Goodness-of-Fit and Contingency Tables
Time management School of Rock.
Calendar of 2012 ESL Lesson on Months.
JANUARY 2018 SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
Sunday Monday Tuesday Wednesday Sunday Monday Tuesday Wednesday
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
Number of visitors to the library.
Time series graphs DESCRIBING THE SEASON.
Functions and Procedures
Sutton Elementary HISD
Higher order questions
Statistics Time Series
MY FUNDAY.
Repetition In today’s lesson we will look at:
Several Ad-Supported TV Shows & Sports “Own” Specific
Ad-Supported TV Accounted For Nearly 8 Of The Top 10 Trending Twitter Topics Throughout Primetime Hours Even though this analysis was done during the mid-October.
Year 2 Spring Term Week 8 Lesson 4
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own.
Days of the Week Monday Tuesday Wednesday Friday Thursday Saturday
Today: Surviving in a Post-Zombie World
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
Decisions In today’s lesson we will look at:
Directed Numbers Friday, 12 April 2019.
Vocabulary January 30 – February 3.
Created by: Ramona Lewis-Dailey
JANUARY 2018 SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
Unit 3 Year 2 – Part B Lesson 1 - Practice.
Extended Christmas Hours Thursday December 8th 9am -6:30pm Friday December 9th 9am -6:30pm Saturday December 10th 9am-6pm Thursday December.
| January Sunday Monday Tuesday Wednesday Thursday Friday
Welcome to the Library.
Year 2 Spring Term Week 8 Lesson 4
At Least Two-Thirds Of The Top 10 Trending Topics
Exploring Computer Science Lesson 4-10 – Part 2
Author visit- Patricia Polacco
Time 1.
冀教版 六年级下册 Lesson 9 Eat More Vegetables and Fruit!.
Contact
A M P M Name: ________ Fluency Log Week of __/__/__ Monday Tuesday
#teacher5aday Stress Awareness Month
Approaching standards
Created by: Ramona Lewis-Dailey
Monday, January 11 WINTER Bell Ringers Template.
NOVEMBER READING LOG Student: When you have read, record your minutes and have your parent initial the proper box (each day). At the end of the month,
7th Grade Math Warm-ups Week of December 5-9, 2016.
DECEMBER READING LOG Student: When you have read, record your minutes and have your parent initial the proper box (each day). At the end of the month,
WEEK 1 Monday Tuesday Wednesday Thursday Friday Saturday Sunday
Rainbow [VT 1] Lesson 1 Today is Monday
2011年 5月 2011年 6月 2011年 7月 2011年 8月 Sunday Monday Tuesday Wednesday
Lesson 7 On the School Bus
Monday Tuesday Wednesday Thursday Friday
June Sunday Monday Tuesday Wednesday Thursday Friday Saturday
READ TO SELF We will read silently to increase stamina, fluency and comprehension and write a one sentence summary. The main.

BOOKINGS – Monday, 2nd July BAYWAVE
January Monday Tuesday Wednesday Thursday Friday Saturday Sunday 30 31
Presentation transcript:

Random Numbers In today’s lesson we will look at: why we might want a random number whether they really are random how to create and scale random numbers in Python

Why Random Numbers? Random things are unpredictable You might want to add randomness to a program so that it doesn’t behave in the same way every time. Some people think that randomness makes things seem more “real” or “human” – e.g. making things wobbly. You might want to simulate or model an actual random event – e.g. a dice throw

Examples A tree drawn in Scratch using recursion The same program with added randomness

Can a Computer Do That? Random numbers are unpredictable, but computers always follow rules A computer can’t really create random numbers – it uses rules to create pseudo-random numbers The computer might use all sorts of variables that change – e.g. the time – to help it create numbers that appear to be random.

Programming Randomness Most programming languages (and also spreadsheets and other applications) only give you a number from 0 to 1. In BASIC, for example, the following program would print a random number: X = RND(1) PRINT X Excel is very similar. Python doesn’t work like that, though.

Python Example The first thing you need to do is import the random library using the following code: from random import randint You can then use the randint() function, e.g. to simulate the roll of a die you could use: die = randint(1,6) That would give you a random integer from 1 to 6

Random Things What happens if you want a random thing that isn’t a number, for example a random day, or a random person from your class? You can number the days, people, etc., and put their names into a list or tuple. You can then produce a random number and use that as the index to look up the name.

Example? To give a random day of the week: from random import randint day = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") for i in range(10): print(day[randint(0,6)])

Distribution All of the examples so far produce random numbers with a linear distribution – i.e. they should be spread evenly throughout the chosen range. What about if you wanted it to be more likely that you’d get a small number (or a large one)? Think about square numbers – 1, 2, 4, 9, 16, 25, 36, 49, 64, 81, 100, etc. – how are they spaced? You can change the distribution of random numbers by raising them to a power.