






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The concept of random numbers and their application in finding minimum and maximum values of functions using a graphing calculator. The document also discusses the difference between pseudo and quasi random number generators and their uses in various applications. The author uses examples from calculus and MatLab to illustrate the concepts.
What you will learn
Typology: Study notes
1 / 11
This page cannot be seen from the preview
Don't miss anything!
A Random Number is an unbiased choice for a number and is not more likely to be
one number than another. A random number must be given some sort of boundaries
for which the random number is chosen. Specific qualities must be given to the
number such as: real, whole, rational, natural, positive, greater than 73.35... etc.
Truly random numbers are chosen once and then forgotten so that no other random
numbers can be chosen based off of that previously chosen random number. Some
uses of random numbers include: choosing a random winner for a contest, encryption
and decryption, selection of jurors, as well as any other situation in which fairness is
required.
Imagine you are extremely rich and would like to give away $1,000 to 1 household
in your neighborhood of about 30 houses. How would you decide which house to
pick? You would have some bias when driving or walking down the road. Some
biases include: “Wow that house is nice!” “My feet are killing me..” “I’ve never met
the people who live there before” “Hey that family is outside now”.. The list could
go on forever. One of the best methods to give to a truly random household would
be to label the houses 1-30 on a map. Then write down 1-30 on slips of paper and
remove your house number. Then put the 29 other pieces into a hat. Give your hat a
shuffle. Finally pick a slip of paper out of the hat. Find the house with that number.
Then don’t even think about doing a re-do. Just go give them their money. That
person won. This was an example of a discrete small sample size for a random choice.
Some cases require truly random selection from a much larger group of people.
Say, for example, the entire population of United States citizens who are 18 years
old or older. You may have wondered in the past how courts choose who will be
summoned as a juror. They use your Social Security Number.
2 Random Number Generators(RNGs)
The goal of a Random Number Generator is to provide numbers to be independent
of each other and not identically distributed. They use a Random Number Generator
to generate 9 numbers per try from 1-9 inclusive. They then have requirements that
their RNG knows such as all digits cannot be the same digit (E.g. 333-33-3333). The
court must also have the SSNs of residents close to the area in which they are located.
If the RNG generates one of these numbers and they have not previously served, then
they summon this person.
There are two main types of Random Number Generators. Neither of which
actually are truly Random. The first of the two is a Pseudo RNG. With a pseudo
RNG, numbers are generated based on the previous number. The first number, a
seed, produces the numbers with an iteration in the following form:
xi = axi− 1 + b(mod m)
ui =
xi m
Where a is a multiplier; b is an offset; m is the modulus; m-1 is the period of the
generator; and u is the number generated. An example of a pseudo-random number
generator is below. The first 10 numbers generated with x 0 = 7 (our seed) is below.
xi = 17xi− 1 (mod 33)
ui =
xi 33
x u 20 0. 10 0. 5 0. 19 0. 26 0. 13 0. 23 0. 28 0. 14 0. 7 0. With a Quasi RNG, numbers are generated to be “equally distributed” or fill in
the missing holes that a pseudo RNG would not fill.
function maximum = Maximum(A, B, C, D, a , b , g , n ) % Max : Find t h e Maximum o f a f u n c t i o n % Given t h e i n t e r v a l [ a , b ] % Generate Random Numbers f o r t h e x−v a l u e s between t h e i n t e r v a l , % s t a r t i n g w i t h t h e g u e s s , and u s i n g t h e s e x−v a l u e s % t o f i n d t h e y−v a l u e s o f t h e f u n c t i o n % The l a r g e s t v a l u e i n t h e a r r a y o f y−v a l u e s w i l l be our Minimum % A, B, C,D r e f e r s t o f ( x)=Axˆ3+Bxˆ2+Cx+D % [ a , b ] : i n t e r v a l % g : g u e s s % n : number o f random numbers % Example u s a g e : % Maximum( 1 , 3 , −9, 7 , −3.841463 , −1.890244 , −3.109756 , 10000) X=1:n ;Y=1:n ; x=g ; x=mod ( 1 6 8 0 7. ∗ x , 2 ˆ 3 1 − 1 ) ; for i =1:n X( i )=a+(b−a ). ∗ ( x / ( 2 ˆ 3 1 − 1 ) ) ; Y( i )= A∗X( i )ˆ3+B∗X( i )ˆ2+C∗X( i )+D; x=mod ( 1 6 8 0 7. ∗ x , 2 ˆ 3 1 − 1 ) ; end [M, I ] = max(Y) ; maximum=[X( I ) M] ; end
function minimum = Minimum(A, B, C, a , b , g , n ) % Min : Find t h e Minimum o f a f u n c t i o n % Given t h e i n t e r v a l [ a , b ] % Generate Random Numbers f o r t h e x−v a l u e s between t h e i n t e r v a l , % s t a r t i n g w i t h t h e g u e s s , and u s i n g t h e s e x−v a l u e s % t o f i n d t h e y−v a l u e s o f t h e f u n c t i o n % The l o w e s t v a l u e i n t h e a r r a y o f y−v a l u e s w i l l be our Minimum % A, B,C r e f e r s t o f ( x)=Axˆ2+Bx+C % [ a , b ] : i n t e r v a l % g : g u e s s % n : number o f random numbers % Example u s a g e : % Minimum ( 1 , −5, 12 , 1. 9 3 1 8 1 8 2 , 2. 8 4 0 9 0 9 1 , 2. 3 8 6 3 6 3 6 , 10000) X=1:n ;Y=1:n ; x=g ; x=mod ( 1 6 8 0 7. ∗ x , 2 ˆ 3 1 − 1 ) ; for i =1:n X( i )=a+(b−a ). ∗ ( x / ( 2 ˆ 3 1 − 1 ) ) ; Y( i )= A∗X( i )ˆ2+B∗X( i )+C; x=mod ( 1 6 8 0 7. ∗ x , 2 ˆ 3 1 − 1 ) ; end [M, I ] = min(Y) ; minimum=[X( I ) M] ; end
MatLab Function call:
To find the Minimum with Calculus, we use the formula:
x =
−b 2 a
where
f (x) = ax^2 + bx + c
is the standard form of a quadratic equation. We then find the function’s value at
the x value from the x = formula.
In our example, f (x) = x^2 − 5 x + 12, so x = 52 and f (x) = (^52 )^2 − 5(^52 ) + 12 = (^234)
We then found the following for our errors:
Actual Minimum: (2.5, 5.75)
Error for Graphing Calculator: 0.
Error for MatLab Code: 0
4 Other Random Number Applications
Another program I created in the language of AutoHotkey, open source located at https://autohotkey.com/. My goal for the program was to create a program to type random digits with random font sizes. I first randomly generated 35 sizes 8-32. Then randomly generated 35 digits 0-9. With the help of https://www.random.org/ this was an easy task. My favorite part about AutoHotkey is that the code is very easy to understand. I gave comments before each of the steps the code takes denoted by a semicolon at the front of the line, then a large arrow to get the reader’s attention. The .ahk file is below. Feel free to copy, paste and save as literally anything with the file extension ”ahk” such as ”RN.ahk” in order to test the code. Also you will need to download and install AHK from the above link in order to run ahk files. More than likely the ”default” position for your Font button will not work, so you must set it with hovering over the font button then pressing (without pressing shift) the key to the left of ”1” (named backquote or backtick). You must have the file running when you do this with of course Google Slides with a new slide up with a text field. Then you press F1 to Start/resume, and if needed during the program, press Esc to Pause.
;−−−−−−−−−−−−−−−−−−−−−−−−−−−>set random s i z e s and d i g i t s i n t o an a r r a y S i z e s : = [ 2 0 , 1 6 , 2 9 , 2 6 , 2 4 , 9 , 1 9 , 2 6 , 1 0 , 2 5 , 1 9 , 2 5 , 2 2 , 3 1 , 2 3 , 3 0 , 2 9 , 2 7 , 8 , 1 3 , 3 1 , 1 4 , 1 8 , 2 9 , 2 1 , 2 0 , 1 1 , 1 5 , 2 0 , 1 6 , 2 4 , 1 3 , 2 0 , 1 3 , 2 2 ] D i g i t s : = [ 9 , 5 , 3 , 0 , 2 , 3 , 8 , 9 , 2 , 7 , 7 , 7 , 7 , 4 , 5 , 0 , 4 , 1 , 4 , 1 , 4 , 8 , 0 , 6 , 7 , 4 , 7 , 4 , 2 , 9 , 6 , 2 , 4 , 6 , 0 ] x :=799 ; D e f a u l t x p o s i t i o n for f o n t button y :=180 ; D e f a u l t y p o s i t i o n for f o n t button Pause Loop 35 { s i z e := S i z e s. pop ( ) d i g i t := D i g i t s. pop ( ) ;−−−−−−−−−−−−−−−−−−−−−−−−−−−>a c t i v a t e window then c l i c k SetTitleMatchMode , 2 WinWait , Google S l i d e s , IfWinNotActive , Google S l i d e s , , WinActivate , Google S l i d e s , WinWaitActive , Google S l i d e s ,
MouseClick , l e f t , %x%, %y% S l e e p , 1000 ;−−−−−−−−−−−−−−−−−−−−−−−−−−−>type s i z e Send , %s i z e% { Enter } S l e e p , 1000 ;−−−−−−−−−−−−−−−−−−−−−−−−−−−>type number Send , %d i g i t% } ;−−−−−−−−−−−−−−−−−−−−−−−−−−−>g i v e s t he a b i l i t y t o Pause / resume with Esc /F1 keys Esc : : Pause , on F1 : : Pause , o f f ;−−−−−−−−−−−−−−−−−−−−−−−−−−−>set p o s i t i o n o f t h e f o n t button ‘ : : MouseGetPos , x , y ; key t o t he l e f t o f ”1”
The following code with provided picture is from a random walk which this code will execute 10,000 random walks to determine the average time it takes for the walk to exceed the y-boundaries. A random walk is where, in this case a graph on the integer number line, we start at 0 and then either increase or decrease by 1 with equal likelihood until we exceed some pre-determined boundaries (below and above the x-axis such as [-2, 5]). Feel free to copy, paste and save as RandomWalk.m in order to test the code. You will of course need MatLab installed to run this code. function [A] = RandomWalk ( b , a ) % E x e r c i s e 9. 3 #2 i n Numerical A n a l y s i s by Tim Saur % use Monte Carlo t o e s t i m a t e how many s t e p s t o r e a c h % −b or a o f g i v e n i n t e r v a l [−b , a ] w i t h a random walk % ( a ) [ −2 ,5] ( b ) [ −5 ,3] ( c ) [ −8 ,3] % Example u s a g e : ( i n p u t −b , not b! ) % RandomWalk ( 2 , 5 ) % RandomWalk ( 5 , 3 ) % RandomWalk ( 8 , 3 ) E x i t s =0; EscTime = 1 : 1 0 0 0 0 ; for n =1: w=0; Count =0; while (w˜=a && w˜=−b ) Count=Count +1; i f rand>1/ w=w+1; e l s e w=w−1; end i f (w==a | | w==−b ) E x i t s=E x i t s +1; EscTime ( n)=Count ; end end %w h i l e AvgEscTime=sum( EscTime ) / 1 0 0 0 0 ; e r r = abs ( a∗b−AvgEscTime ) ; A=[AvgEscTime e r r ] ;
end %f o r
end %f u n c t i o n
5 Conclusion
Throughout history, if one person said to another “hey, pick up a random rock for
me”, whether it be Babylonians in 1800 BCE (probably on Earth’s ground..) or
Astronauts in year 3000 (on some celestial object), there will always be a use for
the word “Random”. Random numbers can be helpful in many different applica-
tions such as keeping credit card information safe, helping calculate minimums and
maximums, and filling your want for a random natural number between a certain
bounded interval. I decided to look more in depth on Random numbers and the
Graphing Calculator because I found them interesting as I use random numbers
every day in coding, in gaming, and even for things I didn’t know used Random
Numbers such as Credit Card Encryption.
6 Acknowledgements
Without Dr. Cazacu’s assistance with the research of random numbers and concepts
to show the reader, I would not have been able to write this project. I really
appreciate all of her guidance.
7 Bibliography
References
[1] Diehm, Adam. “Free Online Comma Separating Tool”. http://Delim.co/
[2] Frenkel, Edward. “An Excerpt from the Book Love and Math.” https://math.
berkeley.edu/∼frenkel/RSA.pdf
[3] Frenkel, Edward. “Prime Numbers and Pierre Fermat Keep Your Secrets
Safe Online.” Slate Magazine, Slate, 3 June 2013, http://www.slate.com/ articles/health and science/science/2013/06/online credit card security the rsa algorithm prime numbers and pierre fermat.html.
[4] Haahr, Mads. “True Random Number Service.” RANDOM.ORG - True Random
Number Service, www.random.org.
[5] Sauer, Tim. Numerical Analysis. Pearson Addison Wesley, 2006.