1
$\begingroup$

When I generate a random number using the following procedure:

set.seed(123)
rnorm(1)

I would like to know what exactly is happening in this case? Is R reading from a table of random numbers? What exactly is 123 referring to? Is it possible to access this table to see how it looks?

$\endgroup$
3
  • 4
    $\begingroup$ Try ?RNG and then look at the references. R does not read from a table, it uses a variety of random number generation methods. You can also find the C code that rnorm uses here $\endgroup$
    – Peter Flom
    Jul 29, 2013 at 16:43
  • 2
    $\begingroup$ In fact R use a variety of pseudo-random number generators. It is not feasible to generate truly random numbers using a computer. Have a look at Christian Robert and George Casella's book (Introducing Monte Carlo Methods with R). $\endgroup$
    – PAC
    Jul 29, 2013 at 17:29
  • 2
    $\begingroup$ See also this very interesting post by Christian Robert : xianblog.wordpress.com/2009/06/09/random-generators $\endgroup$
    – PAC
    Jul 29, 2013 at 17:33

1 Answer 1

5
$\begingroup$

Peter Flom already provided some links that should address your question but to state the answer directly: No, there is no table but a formula that make it possible to generate a series of apparently random numbers.

To get an idea of what is going on, you might consider some elementary pseudo-random number generators like the middle-square method or the linear congruential generator. The latter is deceptively simple and pretty common in general programming languages (probably not in serious statistical applications, though).

The details vary a little but these formulas (and others of the same kind) define a series of deterministic but apparently random values. As each number is generated using the previous one, the system simply saves the last number to pick the next one in the series. The seed, 123, is a way to reset this internal state to some known value to be able to reproduce a given series.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.