1

I'm not sure StackOverflow is the right place to ask this question, because this question is half-programming and half-mathematics. And also really sorry if my question is stupid ^_^

I'm studying about Monte Carlo simulations via the "Monte Carlo Methods" book. One of the first thing I must learn is about Random Number Generator. The basic algorithm of RNG is:
1. Initialize: Draw the seed S0 from the distribution µ on S. Set t = 1.
2. Transition: Set St = f(St−1).
3. Output: Set Ut = g(St).
4. Repeat: Set t = t+ 1 and return to Step 2.

(µ is a probability distribution on the finite set of states S, the input is S0 and the random number we desire it the output Ut)

It is not hard to understand, but the problem here is I don't see the random factor which lie in the number of repeat. How can we decide when to stop the loop of the RNG? All examples I read which implement a RNG are loop for 100 times, and they returns the same value for a specific seed. It is not random at all >_<

Can someone explain what I'm missing here? Any help will be appreciated. Thanks everyone

Anh Tuan
  • 1,728
  • 1
  • 13
  • 25

2 Answers2

2

You can't get a true sequence of random numbers on a computer, without specialized hardware. (Such specialized hardware performs the equivalent of an initial roll of the dice using physics to provide the randomness. Electronic ones often use the electronic noise of specialized diodes at constant temperatures; others use radioactive decay events.)

Without that specialized hardware, what you can generate are pseudorandom numbers which, as you've observed, always generate the same sequence of numbers for the same initial seed. For simple applications, you can often get away with generating an initial seed from the time of invocation, which is effectively random.

And when I say "simple applications," I am excluding cryptography. (Not just that, but especially that.)

Novak
  • 4,687
  • 2
  • 26
  • 64
1

Sometimes when you are trying to debug a simulation, you actually want to have a reproducible stream of "random" numbers so you might specifically sent a stream to start with a specific seed.

For instance in the answer Creating a facet_wrap plot with ggplot2 with different annotations in each plot rcs starts the answer by creating a reproducible set of data using the R code

set.seed(1)
df <- data.frame(x=rnorm(300), y=rnorm(300), cl=gl(3,100))   # create test data

before going on to demonstrate how to answer the actual question.

Community
  • 1
  • 1
Sean
  • 3,765
  • 3
  • 26
  • 48