Skip to main content

Part of the book series: Texts in Computational Science and Engineering ((TCSE,volume 6))

  • 13k Accesses

Abstract

Random numbers have many applications in science and computer programming, especially when there are significant uncertainties in a phenomenon of interest. The purpose of this chapter is to look at some practical problems involving random numbers and learn how to program with such numbers. We shall make several games and also look into how random numbers can be used in physics. A particularly important topic is Monte Carlo simulation for estimating probabilities.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 59.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    In the half open interval [0,1) the lower limit is included, but the upper limit is not.

  2. 2.

    What it means to view the numbers as random has fortunately a firm mathematical foundation, so don’t let the fact that random numbers are deterministic stop you from using them.

  3. 3.

    Textbooks in statistics teach you that it is more appropriate to divide by n−1 instead of n, but we are not going to worry about that fact in this book.

  4. 4.

    For example, the blood pressure among adults of one gender has values that follow a normal distribution.

  5. 5.

    This term is also applied for programs that solve equations arising in mathematical models in general, but it is particularly common to use the term when random numbers are used to estimate probabilities.

  6. 6.

    “As far as the laws of mathematics refer to reality, they are not certain, as far as they are certain, they do not refer to reality.” –Albert Einstein, physicist, 1879–1955.

  7. 7.

    You may try this yourself: flip the coin and make one step to the left or right, and repeat this process.

  8. 8.

    These actions require from scitools.std import * and import time.

  9. 9.

    The probability is \(2^{-n_{s}}\), which becomes about 10−9 for 30 steps.

  10. 10.

    The number of bins in the histogram is just based on the extent of the particles. It could also have been a fixed number.

  11. 11.

    If you want to run this command from an IPython session, prefix convert with an exclamation mark: !convert.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2012 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Langtangen, H.P. (2012). Random Numbers and Simple Games. In: A Primer on Scientific Programming with Python. Texts in Computational Science and Engineering, vol 6. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-30293-0_8

Download citation

Publish with us

Policies and ethics