Random Number Generators

Function that generates uniformly-distributed random numbers.

Remember — RNG functions implemented as computer programs aren’t truly random, only pseudo random. All computers are deterministic (same input always gives the same output).

Example: Why?

This is the lead-up to Monte Carlo algorithms; which are algorithms which use probability to solve complex problems.

AsideChaotic Functions: Tiny changes in the input generate unpredictable changes in the output.

Example: Background

UNIX uses this pseudo RNG:

x_0 = \text{seed} \\ y = x_{n+1} = (Ax_n + B) \mod 2^{31}

You usually want to pick an A and B that are coprime (they don’t share any common factors), because TODO.

Note — Professor recommends using Random.org for randomness, because they tap into real physical processes for their randomness.

Monte Carlo Integration

Problem: Compute the integral.

Example: Derivation of Monte Carlo Integration

We previously approximated the integral using [\frac{(f(a) + f(b))(b-a)]}{2}

The whole point of f(a) + f(b) is to poorly estimate the height.

Instead, we can TODO ??? use random points somehow ??? TODO; which changes the approximation to

\frac{(\sum_i^n f(x_i)}{n}(b-a)

Aside — Randomness

It is SUPER important that you select these points (TODO which points?) random. Otherwise, you are introducing bias.

Remember — Every time you use bias, there is a way to fool the selection method you use.

Now, we increase accuracy by increasing the number of points, rather than increasing the number of trapezoids, which is less work.


Example: Problem

Q:

f(x) = x^2 + 3 + 1, \quad a=1, \quad b=2

A:

Here are the random numbers we’ll use:

1.39345
1.59651
1.96963
1.91880
1.79424
1.95752
1.83763
1.57461
1.63042
1.07487

Note — We just generated this numbers with Random.org, by adding one to the floating points it gave us, to get it in range.

\int_1^2 f(x) dx = 8.75132501248

TODO then, written below was 7.8\overline{3}, why???

You’ll find out this is worse than Richardson’s for this simple problem. But, multi-variable ??? functions benefit greatly.

=== Professor now began talking about 3D area under a shape? ===

If you do this like the trapezoid problem, you’ll be doing a crapton more work computing tons of little prisms.

If you do this with Monte Carlo, the work stays the same.