Waiting times

| assignment (postscript) | (pdf) |


How to make random numbers

C

Tutorial on random numbers

rand.h, a useful little header file that defines useful functions ranf, ranu, rani, rann.

Octave
help -i rand gives help.

rand (N, M)
  Return a matrix with 
  random elements uniformly 
  distributed on the
  interval (0, 1).
There are several other useful routines, such as randn (sample from normal), discrete_rnd (sample from a discrete distribution), binomial_rnd (sample from binomial), and randperm.
Python
Python has a module called random
R
Random {base} manual page
You can generate directly from a Binomial distribution with parameters N, f using
rbinom(T,N,f)
which returns T draws from the distribution. To simulate T tosses of a single coin, and obtain the list of all T outcomes, use:
rbinom(T,1,f)
Perl
rand() gives a random number between 0 and 1.
#!/usr/bin/perl
$seed = 123;
srand($seed); # initial seed
for ($x=0;$x<10;$x++) {
  print rand() . "\n";
}
shell
echo $RANDOM

From man bash: RANDOM Each time this parameter is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be initialized by assigning a value to RANDOM. If RANDOM is unset, it loses its special properties, even if it is subsequently reset.


Solution

Try to solve the problem yourself before looking at a solution.