Omniadisce

Computational physics 17.1: Random numbers between 0 and 1

Lesson Beginner

Join free to take this lesson

Anyone can look around, but taking a lesson needs a free account. With one, your answers are checked step by step and your progress is saved, so you can stop and pick up where you left off on any device.

11 steps ยท about 25 min

By the end you can

  • Make N random numbers between 0 and 1 with rng.random(N), and between a and b with rng.uniform(a, b, N)
  • Say why a program with a seed prints the same number every time it runs
  • Count how many numbers pass a test with np.sum(u < p)
  • Estimate a probability as the fraction of tries in which something happens

Who it is for: Anyone who has done units 1-16 of this course (or skipped units 1-4), in particular lesson 9.2 (random numbers with a seed), and physics unit 1.

The steps

  1. Numbers between 0 and 1
  2. Ten numbers
  3. The seed, once more
  4. A thousand numbers
  5. Between a and b
  6. Random places on a bench
  7. Probability: a fraction of tries
  8. How often below p?
  9. Fewer tries
  10. Why 0.3?
  11. A fraction of tries

Discussion 0 comments

Log in to join the discussion.

× Enlarged view