0% found this document useful (0 votes)
33 views55 pages

6 Random Montecarlo

The document discusses using a Monte Carlo algorithm to estimate the probability that randomly chosen pairs of numbers up to a given limit n are relatively prime. It describes how the algorithm avoids explicitly calculating all pairs by instead randomly selecting a subset and calculating the probability for that subset. It also addresses issues with generating pseudorandom numbers for the algorithm.

Uploaded by

ashodhiya14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views55 pages

6 Random Montecarlo

The document discusses using a Monte Carlo algorithm to estimate the probability that randomly chosen pairs of numbers up to a given limit n are relatively prime. It describes how the algorithm avoids explicitly calculating all pairs by instead randomly selecting a subset and calculating the probability for that subset. It also addresses issues with generating pseudorandom numbers for the algorithm.

Uploaded by

ashodhiya14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

MAT 685: C++

for Mathemati-
cians

John Perry

Prime pairs,
again
How do we choose?
An aside on
organization MAT 685: C++ for Mathematicians
Implementing Monte
Carlo pairs
Prime pairs in Monte Carlo
“Normal”
random values

Summary
John Perry

University of Southern Mississippi

Spring 2017
MAT 685: C++
for Mathemati-
cians
Outline
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
1 Prime pairs, again
Carlo pairs
How do we choose?
“Normal”
random values An aside on organization
Summary Implementing Monte Carlo pairs

2 “Normal” random values

3 Summary
MAT 685: C++
for Mathemati-
cians
Outline
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
1 Prime pairs, again
Carlo pairs
How do we choose?
“Normal”
random values An aside on organization
Summary Implementing Monte Carlo pairs

2 “Normal” random values

3 Summary
MAT 685: C++
for Mathemati-
cians
Classic problem
John Perry

Prime pairs,
again
• Choose n
How do we choose?
An aside on
• Choose a, b ∈ {1, . . . , n}
organization
Implementing Monte
Carlo pairs
• Let pn be probability that gcd (a, b) = 1
“Normal” • Does lim pn exist?
random values n→∞
Summary • If so, what is its value?
MAT 685: C++
for Mathemati-
cians
Classic problem
John Perry

Prime pairs,
again
• Choose n
How do we choose?
An aside on
• Choose a, b ∈ {1, . . . , n}
organization
Implementing Monte
Carlo pairs
• Let pn be probability that gcd (a, b) = 1
“Normal” • Does lim pn exist?
random values n→∞
Summary • If so, what is its value?

Example
Let n = 8.  
8 8!
• Possible outcomes: = 2!6! = 28
2
• Relatively prime pairs: (1, 2), (1, 3), …, (1, 8), (2, 3), (2, 5),
(2, 7), (3, 4), (3, 5), (3, 7), (3, 8), (4, 5), (4, 7), (6, 7), (7, 8)
• So p8 = 18/28 = 9/14 ≈ 64.3%
MAT 685: C++
for Mathemati-
cians
A problem
John Perry

Prime pairs,
again
How do we choose?
An aside on There are too many numbers! In the words of the two wise sages,
organization
Implementing Monte
Carlo pairs

“Normal”
random values

Summary
MAT 685: C++
for Mathemati-
cians
A problem
John Perry

Prime pairs,
again
How do we choose?
An aside on There are too many numbers! In the words of the two wise sages,
organization
Implementing Monte
Carlo pairs
I’m, like, angry at numbers.
“Normal”
random values Yeah, there’s, like, too many of
Summary them, and stuff.
— Beavis & Butthead
MAT 685: C++
for Mathemati-
cians
A problem
John Perry

Prime pairs,
again
How do we choose?
An aside on There are too many numbers! In the words of the two wise sages,
organization
Implementing Monte
Carlo pairs
I’m, like, angry at numbers.
“Normal”
random values Yeah, there’s, like, too many of
Summary them, and stuff.
— Beavis & Butthead

n → ∞: program takes longer, and longer, and


loooooongerrrrrrr…
MAT 685: C++
for Mathemati-
cians
Probabilistic algorithms
John Perry

Prime pairs,
again
How do we choose?
An aside on
Two major types
organization
Implementing Monte
Carlo pairs
Las Vegas “always correct, probably fast”
“Normal” Monte Carlo “always fast, probably correct”
random values

Summary
MAT 685: C++
for Mathemati-
cians
Probabilistic algorithms
John Perry

Prime pairs,
again
How do we choose?
An aside on
Two major types
organization
Implementing Monte
Carlo pairs
Las Vegas “always correct, probably fast”
“Normal” Monte Carlo “always fast, probably correct”
random values

Summary
Our approach
For large n:
• choose large subset of pairs
• determine how many are rel. prime
• divide by size of subset

Which algorithm type is this?


MAT 685: C++
for Mathemati-
cians
Example
John Perry

Prime pairs,
n = 100
again
How do we choose?
• Choose 10: (rel prime blue)
An aside on
organization
Implementing Monte
Carlo pairs (53, 97) (22, 99) (30, 42)
“Normal” (20, 69) (3, 9) (61, 80)
random values

Summary
(3, 37) (9, 74) (22, 43)
(67, 94)
MAT 685: C++
for Mathemati-
cians
Example
John Perry

Prime pairs,
n = 100
again
How do we choose?
• Choose 10: (rel prime blue)
An aside on
organization
Implementing Monte
Carlo pairs (53, 97) (22, 99) (30, 42)
“Normal” (20, 69) (3, 9) (61, 80)
random values

Summary
(3, 37) (9, 74) (22, 43)
(67, 94)

• estimate: 70%
• actual: 69%

Not bad!
100 · 101
(and much less work than )
2
MAT 685: C++
for Mathemati-
cians
Outline
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
1 Prime pairs, again
Carlo pairs
How do we choose?
“Normal”
random values An aside on organization
Summary Implementing Monte Carlo pairs

2 “Normal” random values

3 Summary
MAT 685: C++
for Mathemati-
cians
How should we choose pairs?
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
Carlo pairs

“Normal”
• no obvious pattern
random values
• “uniform” distribution
Summary

∴ Choose randomly

(of course)
MAT 685: C++
for Mathemati-
cians
Question
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
But how do we generate random numbers?!?
Implementing Monte
Carlo pairs We don’t. We generate pseudo-random numbers.
“Normal”
random values linear congruential generator xn+1 = (axn + b) mod c
Summary
seed x0 (first number in sequence)
MAT 685: C++
for Mathemati-
cians
Question
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
But how do we generate random numbers?!?
Implementing Monte
Carlo pairs We don’t. We generate pseudo-random numbers.
“Normal”
random values linear congruential generator xn+1 = (axn + b) mod c
Summary
seed x0 (first number in sequence)

Example
Let a = 3, b = 7, c = 10, x0 = 2

2, 3, 6, 5, 2, 3, 6, 5, 2, 3, 6
MAT 685: C++
for Mathemati-
cians
Question
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
But how do we generate random numbers?!?
Implementing Monte
Carlo pairs We don’t. We generate pseudo-random numbers.
“Normal”
random values linear congruential generator xn+1 = (axn + b) mod c
Summary
seed x0 (first number in sequence)

Example
Let a = 3, b = 7, c = 10, x0 = 2

2, 3, 6, 5, 2, 3, 6, 5, 2, 3, 6

…not a very good choice!


MAT 685: C++
for Mathemati-
cians
C++ library helps out
John Perry

Prime pairs,
• Pseudo-random generator
again
How do we choose? #include <cstdlib>
An aside on
organization
Implementing Monte
void srand(unsigned seed)
Carlo pairs
int rand()
“Normal”
random values

Summary • use srand() to seed, usually to system time


• rand() result in [ 0, RAND_MAX ]
MAT 685: C++
for Mathemati-
cians
C++ library helps out
John Perry

Prime pairs,
• Pseudo-random generator
again
How do we choose? #include <cstdlib>
An aside on
organization
Implementing Monte
void srand(unsigned seed)
Carlo pairs
int rand()
“Normal”
random values

Summary • use srand() to seed, usually to system time


• rand() result in [ 0, RAND_MAX ]

• System time?

#include <ctime>
time_t time(time_t * storage)

• storage is “address” of optional variable to store


time
• use nullptr for now
MAT 685: C++
for Mathemati-
cians
nullptr?
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
Carlo pairs

“Normal”
random values • C++11 standard for “nowhere”
Summary
• previous conventions: 0, NULL
• conventions, not standards
• avoid these
MAT 685: C++
for Mathemati-
cians
Book offers adaptation
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
Carlo pairs

“Normal” Why?
random values
• specify different interval
Summary
• not just [0, RAND_MAX]
• ways to avoid patterns in certain special sets
• different generator desired? easier to change
MAT 685: C++
for Mathemati-
cians
Interface (p. 1)
John Perry

Prime pairs,
again
How do we choose?
New folder, rand_unif
An aside on
organization
Implementing Monte
Carlo pairs
Listing 1: uniform.hpp (p. 1)
“Normal” #ifndef UNIFORM_HPP
random values #define UNIFORM_HPP
Summary
/** Generate a random number between 0 and 1.*/
double unif();

/**
Generate a random number in a real interval.
@param a one endpoint of the interval
@param b the other endpoint of the interval
@return a uniform random number in [0,1]
*/
double unif(double a, double b);
MAT 685: C++
for Mathemati-
cians
Interface (p. 2)
John Perry

Prime pairs,
again
How do we choose?
Listing 2: uniform.hpp (p. 2)
An aside on
organization /**
Implementing Monte
Carlo pairs
Generate a random integer between 1 and a
“Normal”
random values
given value.
Summary @param n the largest possible value
@return uniform random value in {1,...,n}
*/
long unif(long n);

/** Reset generator based on system clock */


void seed();

#endif
MAT 685: C++
for Mathemati-
cians
Implementation (p. 1)
John Perry

Prime pairs, Listing 3: uniform.cpp (p. 1)


again
How do we choose?
An aside on
#include <ctime>
organization
Implementing Monte
using std::time;
Carlo pairs
#include <cstdlib>
“Normal”
random values using std::rand; using std::srand;
Summary

#include "uniform.hpp"

double unif() {
return rand() / double(RAND_MAX);
}

double unif(double a, double b) {


return (b - a)*unif() + a;
}
MAT 685: C++
for Mathemati-
cians
Implementation (p. 2)
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization Listing 4: uniform.cpp (p. 2)
Implementing Monte
Carlo pairs
long unif(long a) {
“Normal”
random values if (a == 0) return 0;
Summary if (a < 0) a = -a;
return long(unif()*a) + 1;
}

void seed() {
srand(time(nullptr));
}
MAT 685: C++
for Mathemati-
cians
Outline
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
1 Prime pairs, again
Carlo pairs
How do we choose?
“Normal”
random values An aside on organization
Summary Implementing Monte Carlo pairs

2 “Normal” random values

3 Summary
MAT 685: C++
for Mathemati-
cians
Organizing files
John Perry

• It is common to organize source files in folders and


Prime pairs,
again subfolders.
How do we choose?
An aside on
organization
• Currently, though, we have a mess:
Implementing Monte
Carlo pairs
c++_main
“Normal”
random values gcd
Summary gcd.hpp
gcd_recursive.cpp
gcd_while.cpp
prob_relprime_pair.cpp
test_gcd_recursive.cpp
test_gcd_while.cpp
test_xgcd.cpp
rand_unif
uniform.cpp
uniform.hpp
MAT 685: C++
for Mathemati-
cians
How to access both sets of files?
John Perry
Monte Carlo approach needs both gcd and uniform files. They
Prime pairs,
again
are in different folders.
How do we choose?
An aside on
organization
Implementing Monte
Carlo pairs

“Normal”
random values

Summary
MAT 685: C++
for Mathemati-
cians
How to access both sets of files?
John Perry
Monte Carlo approach needs both gcd and uniform files. They
Prime pairs,
again
are in different folders.
How do we choose?
An aside on
• Create new folder relprime_pairs
organization
Implementing Monte
• move prob_relprime_pair.cpp in
Carlo pairs
• no longer compiles; we can fix it
“Normal”
random values

Summary
MAT 685: C++
for Mathemati-
cians
How to access both sets of files?
John Perry
Monte Carlo approach needs both gcd and uniform files. They
Prime pairs,
again
are in different folders.
How do we choose?
An aside on
• Create new folder relprime_pairs
organization
Implementing Monte
• move prob_relprime_pair.cpp in
Carlo pairs
• no longer compiles; we can fix it
“Normal”
random values
#include “/path/to/filename” can use absolute or relative paths
Summary
to an interface
• change #include ``gcd.hpp'' to #include
``../gcd/gcd.hpp''
• compilation:
$ cd relprime_pairs
$ g++ -o prob_relprime_pair \
../gcd/gcd_while.cpp \
prob_relprime_pair.cpp
$ ./prob_relprime_pair
MAT 685: C++
for Mathemati-
cians
Homework
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
Carlo pairs

“Normal”
random values

Summary
pp. 63–65 #4.1, 4.4, 4.5
MAT 685: C++
for Mathemati-
cians
Outline
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
1 Prime pairs, again
Carlo pairs
How do we choose?
“Normal”
random values An aside on organization
Summary Implementing Monte Carlo pairs

2 “Normal” random values

3 Summary
MAT 685: C++
for Mathemati-
cians
Monte Carlo method
John Perry

Prime pairs, Place in relprime_pairs folder


again
How do we choose?
An aside on
organization
Listing 5: monte_carlo_pairs.cpp (p. 1)
Implementing Monte
Carlo pairs #include <iostream>
using std::cin; using std::cout;
“Normal”
random values using std::endl;
Summary
#include "../gcd/gcd.hpp"
#include "../rand_unif/uniform.hpp"

int main() {
long n;
long reps; // # times we perform experiment
long a, b; // pairs in {1,..,n}
long count; // number of rel prime pairs

count = 0;
cout << "Enter n (max el of set) --> ";
cin >> n;
MAT 685: C++
for Mathemati-
cians
Monte Carlo method
John Perry

Prime pairs,
again Place in relprime_pairs folder
How do we choose?
An aside on
organization
Implementing Monte
Listing 6: monte_carlo_pairs.cpp (p. 2)
Carlo pairs
cout << "Enter number of pairs to sample --> ";
“Normal”
random values
cin >> reps;

Summary seed();
for (long k = 0; k < reps; ++k) {
a = unif(n);
b = unif(n);
if (gcd(a,b) == 1) ++count;
}

cout << count / double(reps) << endl;

return 0;
}
MAT 685: C++
for Mathemati-
cians
Compiling, executing
John Perry

Compiling… pay attention to dots!


Prime pairs,
again
How do we choose? $ g++ -o monte_carlo_pairs \
An aside on
organization -std=c++11 \
Implementing Monte
Carlo pairs ../gcd/gcd_while.cpp \
“Normal”
random values
../rand_unif/uniform.o \
Summary
monte_carlo_pairs.cpp

(may need -std=c++11 to avoid complaint about nullptr)


MAT 685: C++
for Mathemati-
cians
Compiling, executing
John Perry

Compiling… pay attention to dots!


Prime pairs,
again
How do we choose? $ g++ -o monte_carlo_pairs \
An aside on
organization -std=c++11 \
Implementing Monte
Carlo pairs ../gcd/gcd_while.cpp \
“Normal”
random values
../rand_unif/uniform.o \
Summary
monte_carlo_pairs.cpp

(may need -std=c++11 to avoid complaint about nullptr)

Executing
$ ./monte_carlo_pairs
Enter n (max el of set) --> 100000
Enter number of pairs to sample --> 1000
0.595
MAT 685: C++
for Mathemati-
cians
Comparison
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte Estimate: 0.595
Carlo pairs

“Normal”
Actual: 0.614747
random values
• prob_relprime_pairs takes a long time to find it
Summary
• can get different estimates, too:
• different execution times
• different values of reps
• can approximate correct value w/many estimates faster
than finding exact
MAT 685: C++
for Mathemati-
cians
Outline
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
1 Prime pairs, again
Carlo pairs
How do we choose?
“Normal”
random values An aside on organization
Summary Implementing Monte Carlo pairs

2 “Normal” random values

3 Summary
MAT 685: C++
for Mathemati-
cians
Not all distributions are uniform
John Perry

Prime pairs, “Normal” random variables are Gaussian:


again
How do we choose?
An aside on
organization
Implementing Monte
Carlo pairs

“Normal”
random values

Summary

1 t2
f (t) = √ · e− 2

MAT 685: C++
for Mathemati-
cians
Probabilistic properties
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization

´
Implementing Monte
Carlo pairs

“Normal”
´ R f dt = 1 area under curve
random values
´ R tf2 dt = 0 mean
Summary
R t f dt = 1 standard deviation
MAT 685: C++
for Mathemati-
cians
Probabilistic properties
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization

´
Implementing Monte
Carlo pairs

“Normal”
´ R f dt = 1 area under curve
random values
´ R tf2 dt = 0 mean
Summary
R t f dt = 1 standard deviation
ˆ x
define Φ (x) = P |X ≤ x| = f (t) dt
−∞
MAT 685: C++
for Mathemati-
cians
Generating normal random values
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
Carlo pairs
Box-Muller method
“Normal” generate (x, y) uniformly in unit disc
random values
let r
Summary p −2 ln r
r = x 2 + y2 , µ = , z = µx
r
return z
MAT 685: C++
for Mathemati-
cians
Generating normal random values
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
Carlo pairs
Box-Muller method
“Normal” generate (x, y) uniformly in unit disc
random values
let r
Summary p −2 ln r
r = x 2 + y2 , µ = , z = µx
r
return z

Remark
y = µy would also be random value
MAT 685: C++
for Mathemati-
cians
static “remembers” values
John Perry

Prime pairs,
again Listing 7: memories.cpp
How do we choose?
An aside on #include <iostream>
organization
Implementing Monte
using std::cin; using std::cout; using std::endl;
Carlo pairs

“Normal” int memory(int val) {


random values static int last_val; // static, so "remembers"
Summary int ret_val = last_val; // temporary
last_val = val; // replace
return ret_val; // return
}

int main() {
for (int i = 0; i < 10; ++i) {
int new_val;
cout << "Enter #" << i << ": ";
cin >> new_val;
cout << "I remember " << memory(new_val) << endl;
}
}
MAT 685: C++
for Mathemati-
cians
Compiling, executing
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
$ g++ -o memories memories.cpp
Carlo pairs
$ ./memories
“Normal”
random values Enter #0: 5
Summary I remember 0
Enter #1: 3
I remember 5
Enter #2:
MAT 685: C++
for Mathemati-
cians
Compiling, executing
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
$ g++ -o memories memories.cpp
Carlo pairs
$ ./memories
“Normal”
random values Enter #0: 5
Summary I remember 0
Enter #1: 3
I remember 5
Enter #2:

…now back to normal random values!


MAT 685: C++
for Mathemati-
cians
Interface
John Perry

Prime pairs,
again New folder, rand_norm
How do we choose?
An aside on
organization
Implementing Monte
Listing 8: randn.hpp
Carlo pairs

“Normal”
#ifndef RANDN_HPP
random values #define RANDN_HPP
Summary

/**
Generate a random number between -1 and 1
according to a normal distribution.
*/
double randn();

#endif
MAT 685: C++
for Mathemati-
cians
Implementation
John Perry

Prime pairs,
again Listing 9: randn.cpp (p. 1)
How do we choose?
An aside on #include <cmath>
organization
Implementing Monte
using std::sqrt;
Carlo pairs

“Normal” #include "../rand_unif/uniform.hpp"


random values

Summary double randn() {


static bool has_saved = false;
static double saved;

// use saved value, if we have one


if (has_saved) {
has_saved = false;
return saved;
}

// pick a point within unit disk


double x, y;
double r = 2.0;
MAT 685: C++
for Mathemati-
cians
Implementation
John Perry

Prime pairs,
again
How do we choose? Listing 10: randn.cpp (p. 2)
An aside on
organization
while (r > 1.0) {
Implementing Monte
Carlo pairs x = unif(-1.0, 1.0);
“Normal” y = unif(-1.0, 1.0);
random values r = x*x + y*y;
Summary
}

// rescale by Box-Muller
r = sqrt(r);
double mu = sqrt(-2.0 * log(r) / r);

// save y value, return x value


saved = mu*y;
has_saved = true;

return mu*x;
}
MAT 685: C++
for Mathemati-
cians
Program to compare
John Perry
Place in parent folder
Prime pairs,
again
How do we choose?
Listing 11: random_comparisons.cpp
An aside on
organization #include <iostream>
Implementing Monte
Carlo pairs
using std::cout; using std::endl;
“Normal”
random values
#include "rand_unif/uniform.hpp"
#include "rand_norm/randn.hpp"
Summary

int main() {
seed();

cout << "Uniform:\n";


for (int i = 0; i < 20; ++i)
cout << unif(10) << ',';
cout << endl;

cout << "Normal:\n";


for (int i = 0; i < 20; ++i)
cout << long(randn()*10/4) + 5 << ',';
cout << endl;
}
MAT 685: C++
for Mathemati-
cians
Compiling, executing
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
$ g + + −o random_comparisons r a n d _ u n i f / u n i f o r m . o \
Carlo pairs
rand_norm / randn . o random_comparisons . cpp
“Normal” $ . / random_comparisons
random values
Uniform :
Summary
9 ,4 ,8 ,8 ,10 ,2 ,4 ,8 ,3 ,6 ,5 ,7 ,4 ,6 ,10 ,10 ,7 ,8 ,2 ,7 ,
Normal :
5 ,5 ,4 ,5 ,5 ,7 ,6 ,3 ,8 ,5 ,5 ,5 ,4 ,6 ,5 ,7 ,5 ,6 ,3 ,4 ,
$
MAT 685: C++
for Mathemati-
cians
Compiling, executing
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
$ g + + −o random_comparisons r a n d _ u n i f / u n i f o r m . o \
Carlo pairs
rand_norm / randn . o random_comparisons . cpp
“Normal” $ . / random_comparisons
random values
Uniform :
Summary
9 ,4 ,8 ,8 ,10 ,2 ,4 ,8 ,3 ,6 ,5 ,7 ,4 ,6 ,10 ,10 ,7 ,8 ,2 ,7 ,
Normal :
5 ,5 ,4 ,5 ,5 ,7 ,6 ,3 ,8 ,5 ,5 ,5 ,4 ,6 ,5 ,7 ,5 ,6 ,3 ,4 ,
$

Notice bunching of normal


• 5,6,7 appear 14 times
MAT 685: C++
for Mathemati-
cians
Homework
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
Carlo pairs

“Normal”
random values

Summary
p. 65 #4.6, 4.7
MAT 685: C++
for Mathemati-
cians
Outline
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization
Implementing Monte
1 Prime pairs, again
Carlo pairs
How do we choose?
“Normal”
random values An aside on organization
Summary Implementing Monte Carlo pairs

2 “Normal” random values

3 Summary
MAT 685: C++
for Mathemati-
cians
Summary
John Perry

Prime pairs,
again
How do we choose?
An aside on
organization • Math stuff
Implementing Monte
Carlo pairs • Monte Carlo algorithms
“Normal”
random values
• Probability distributions
Summary • Pseudorandom generators
• Linear congruential generator
• Box-Muller method
• Programming stuff
• C++ Standard Library: random
• file organization
• static variables

You might also like