previous | start | next

## Simulations

- In actual applications you want to generate random numbers in different ranges, say between `a` and `b`.
- For example, to simulate a die roll, you need numbers between `a =1` and `b = 6`.
- First compute `rand() % (b - a + 1)` to obtain a random value between 0 and `b - a`.
- Add that to `a` to yield a random value between `a` and `b`.

  >     int rand_int(int a, int b)
  >     {
  >        return a + rand() % (b - a + 1);

  >     }

previous | start | next