Compunet Corporation Programming with Visual Basic.NET Random Number Week # 12 Tariq Ibn Aziz & Kevin Jones.

Slides:



Advertisements
Similar presentations
Computer Science 1620 Function Overloading. Review Question: suppose I have the following function: can I call this function with an integer? yes – compiler.
Advertisements

Digital Image Processing Lecture 3: Image Display & Enhancement
GCSE Computing Working with numbers. Challenge ‘Crimson Mystical Mages’ is a fantasy role playing board game. You need to create an electronic program.
Probability Distributions CSLU 2850.Lo1 Spring 2008 Cameron McInally Fordham University May contain work from the Creative Commons.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 A Simulation Problem Length of room Width of room Start.
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.
Some Hashing Techniques (used to randomize the relative addresses) 1Prepared by Perla P. Cosme.
QUICK MATH REVIEW & TIPS 2
Compunet Corporation1 Programming with Visual Basic.NET Selection Structure If-Else Week 4 Tariq Ibn Aziz.
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
Random Numbers Dick Steflik. Pseudo Random Numbers In most cases we do not want truly random numbers –most applications need the idea of repeatability.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 2 Tariq Aziz and Kevin Jones.
Level ISA3: Information Representation
Pseudorandom Number Generators
Random Number Generation
Hash Tables1 Part E Hash Tables  
1 Section 2.5 Integers and Algorithms. 2 Euclidean algorithm for finding gcd Where L is a larger number, and S is a smaller number, to find gcd(L,S):
Simulation Basic Concepts. NEED FOR SIMULATION Mathematical models we have studied thus far have “closed form” solutions –Obtained from formulas -- forecasting,
Compunet Corporation Programming with Visual Basic.NET GUI Week # 11 Tariq Ibn Aziz.
Random numbers in Python Nobody knows what’s next...
Compunet Corporation1 Programming with Visual Basic.NET Arithmetic, Logical & Bitwise Operators Week # 3 Tariq Ibn Aziz.
Properties of Random Numbers
Section 3.6 BUILT-IN FUNCTIONS involving numbers & strings.
Computer Systems 1 Fundamentals of Computing
Binary Numbers.
REMEMBER: A number can be negative or positive as shown in the number line below: Negative Numbers (-) Positive Numbers (+)
Math 116 Chapter 12.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
CS105 INTRODUCTION TO COMPUTER CONCEPTS BINARY VALUES & NUMBER SYSTEMS Instructor: Cuong (Charlie) Pham.
MATH 224 – Discrete Mathematics
MATH AND RANDOM CLASSES.  The need for random numbers occurs frequently when writing software.  The Random class, which is part of the java.util class,
ECE 3110: Introduction to Digital Systems Number Systems.
Data Representation in Computer Systems. 2 Objectives Understand the fundamentals of numerical data representation and manipulation in digital computers.
CS433 Modeling and Simulation Lecture 15 Random Number Generator Dr. Anis Koubâa 24 May 2009 Al-Imam Mohammad Ibn Saud Islamic University College Computer.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
February 4, 2005 Searching and Sorting Arrays. Searching.
Monte Carlo Methods So far we have discussed Monte Carlo methods based on a uniform distribution of random numbers on the interval [0,1] p(x) = 1 0  x.
Compunet Corporation1 Programming with Visual Basic.NET While, Do and For – Next Loops Week 5 Tariq Ibn Aziz.
Digital Image Processing Lecture 3: Image Display & Enhancement March 2, 2005 Prof. Charlene Tsai.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Techniques in Signal Processing CSC 508 Generating Random Numbers with a Computer.
Chapter 10 Hashing. The search time of each algorithm depend on the number n of elements of the collection S of the data. A searching technique called.
Random Number Generator. Random number Random number: Uniform distribution on [0,1] Random device: dice, coin -> cannot generate the equal sequence.
Homework #2: Functions and Arrays By J. H. Wang Mar. 20, 2012.
Homework #1: C++ Basics, Flow of Control, and Function Basics By J. H. Wang Mar. 13, 2012.
D75P 34R - HNC Computer Architecture Week 4 Signed Integers © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen College unless otherwise.
Subroutines. Harder Problems  Examples so far: sum, sum between, minimum –straightforward computation –small number of intermediate variables –single.
Section 5.1.  Three ways to answer this question: 1. Actually carry out an experiment 2. Develop a probability model 3. Start with a model, and then.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
Random numbers in C++ Nobody knows what’s next....
Lecture 6 Excess Notation. Excess 8 notation indicates that the value for zero is the bit pattern for 8, that is 1000 Excess 8 notation indicates that.
CSci 162 Lecture 7 Martin van Bommel. Random Numbers Until now, all programs have behaved deterministically - completely predictable and repeatable based.
Let’s not leave anything to chance. How that process to generate random numbers takes places requires some complicated statistics that are outside the.
Controlling Program Flow with Decision Structures.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
ECE 2110: Introduction to Digital Systems Number Systems: conversions.
Random numbers. Using Random Number Table 1.Randomly select in the table a 1-digit number. Describe the position of that number (e.g. 5 th row, 13 th.
1.  How does the computer generate observations from various distributions specified after input analysis?  There are two main components to the generation.
ECE 2110: Introduction to Digital Systems Number Systems: conversions.
L131 Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips rand( ) math library functions Reading Sections.
Linear Algebra Review.
5 Rational Numbers: Positive and Negative Decimals.
Number System conversions
Public Key Cryptosystems - RSA
Random numbers Taken from notes by Dr. Neil Moore
Random Number Generation
Random number generators
Random Number and Random Variate Generation
GUI Programming in Visual Studio .NET
Presentation transcript:

Compunet Corporation Programming with Visual Basic.NET Random Number Week # 12 Tariq Ibn Aziz & Kevin Jones

Tariq Aziz & Kevin Jones Random Numbers What is a “random” number? I can ask you to give me a “random” number between 1 and 100. Suppose you respond with “86”. How did you choose that particular number? What algorithm did you use? Suppose I ask you for another random number. How will you choose that one? How can we, as programmers, instruct the computer how to “calculate” a sequence/stream of random numbers?

Tariq Aziz & Kevin Jones Random Numbers Sometimes we, as programmers, need to generate random numbers. For example, in the Birthday Problem, we need to generate a “random” birthday for each person. We can do this simply by generating a “random” number between 1 and 365, inclusive. We can ask the computer to give us a “random” number between 0.0 and 1.0, [0.0, 1.0), and then we can scale the number to get it into a range that we require. In Visual Basic, the function Rnd() will return a number between [0.0, 1.0).

Tariq Aziz & Kevin Jones Random Numbers So, if we want a random integer between 1 and 365, we can do the following: Dim birthday As Integer birthday = int( Rnd() * 365 ) + 1 Let’s look at the right-hand side above in detail: Rnd() gives us a “random” number between [0.0, 1.0) Multiplying by 365 gives us a number between [0.0, 365.0) Conversion to int gives us an int between [0, 364] Finally, adding 1 gives us an int between [1, 365].

Tariq Aziz & Kevin Jones MidSquare Method There are many ways to generate “random” numbers. We’ll take a closer look at the Midsquare method of generating random numbers between [0.0, 1.0). First, we start with a four-digit seed value, for example, We then square it to get a number up to eight digits long. If the number has fewer than eight digits, we pad the left with zeroes until we get eight digits. In our example, 7182^2 gives us Now we choose the “middle” four digits of our result, which is 5811 in our example. We divide by 10,000 to get our first random number, e.g We repeat this process indefinitely…

Tariq Aziz & Kevin Jones MidSquare Method izizi (z i ) 2 Middle four digitsPseudo-random num

Tariq Aziz & Kevin Jones Pseudo-random Numbers It is important that the stream of pseudo-random numbers that we generate appear random, i.e. there is no discernable pattern to the numbers. Consider the stream generated by our previous example: , , , , , , , , … Can you find any pattern in the numbers? Even though the stream is actually computed using a formula, and we’ll get the same stream of numbers if we start with the same seed value, the pseudo-random numbers are “good enough” to use if they “appear” random, as determined by various statistical tests that are beyond the scope of this course…

Tariq Aziz & Kevin Jones Midsquare code 'seed is a four-digit starting value(1000 <= seed <= 9999) 'n is the number of random variates to generate (n > 0) Dim n, seed As Integer'inputs to read from user Dim i, sqr, mid As Integer System.Console.Write("How many random no do you require? ") n = System.Console.Readline() System.Console.Write("Enter 4-digit seed(between ):") seed = System.Console.Readline() mid = seed for i = 1 to n sqr = mid ^ 2'square the four-digit number 'Now choose the "middle 4" digits of sqr sqr = sqr \ 100'lose the right-most 2 digits mid = sqr Mod 10000'keep the new right-most 4-digits System.Console.Writeline(mid / ) next i