JPJC python random module notes
Uploaded by HiThere123 · 10 March 2024
Preview
2024 JC 1 H2 Computing (9569) 1 Random Number Random numbers are useful for a variety of purposes, such as generating data encryption keys, simulating, and modelling complex phenomena and for selecting random samples from larger data sets. They have also been used aesthetically, for example in literature and music, and are of course ever popular for games and gambling. When one single random number is concern, that random number should be selected from a set of possible values , where the selection of every single value in the set is equally probable, i.e., a uniform distribution. However, when considering a sequence of random numbers, the selection of each random value must be statistically independent of the others. Random Number Generator (RNG) With the advent of computers, programmers recognised the need for a means of introducing randomness into a computer program. However, surprising as it may seem, it is difficult to get a computer to do something by chance. Random numbers take on a large role in the world of computing. In real life, a fundamental use of random numbers can be seen in lotteries and lucky draws , where computer programs are used to generate random numbers to `decide the winning tickets. In the world of computing, random numbers can be used to generate data encryption keys, or to select an independent random sample from the data set. A computer follows its instructions blindly and is therefore completely predictable. (A computer that does not follow its instructions in this manner is considered broken.) There are two main approaches to generating random numbers using a computer: 1. Pseudo-Random Number Generators (PRNGs) , 2. True Random Number Generators (TRNGs) . The approaches have distinct characteristics, and each has its pros and cons.
2024 JC 1 H2 Computing (9569) 2 True Random Numbers Random numbers obtained from certain uncontrollable physical phenomena. The physical phenomenon can be very simple, like the little variations in somebody's mouse movements or in the amount of time between keystrokes. A good physical phenomenon to use is a radioactive source. The points in time at which a radioactive source decays are completely unpredictable, and they can quite easily be detected and fed into a computer , avoiding any buffering mechanisms in the operating system. For most real-life applications, a pseudo-random number is sufficient. For example, a CD player in “random” mode is really playing in pseudo-random mode, with a pattern that is discernible if you listen carefully enough. Using pseudo-random numbers is perfectly acceptable in this case because there’s no quantitative advantage in the degree of randomness. Can a computer generate a truly random number? Computers are deterministic devices (i.e. given and using the same input, it will follow a fixed set of instructions and therefore produce the same output). For true random numbers to be generated, the dev
Content continues in the PDF.
Related notes
- VJC Chapter 21 SQLite with PythonNotes/Practices · 2025
- VJC Chapter 23 Web Applications PrinciplesNotes/Practices · 2025
- VJC Chapter 10 RecursionNotes/Practices · 2025
- VJC Chapter 20 SQLNotes/Practices · 2025
- VJC Chapter 16 Hash TableNotes/Practices · 2025
- VJC Chapter 22 NoSQLNotes/Practices · 2025

