Study guide

5.3 Randomization, Random vs. Pseudorandom Numbers, and Scaling to a Range

Praxis Computer Science 5652

Track your progress as you read

Finished sections get a check mark.

1 Chapter 1: Praxis 5652 Exam Overview and ETS Pseudocode

1.1 Praxis 5652 Test Facts, Scoring, and Registration 1.2 Official ETS Pseudocode Notation and Tracing Strategy

2 Chapter 2: Impacts of Computing: Innovation, Access, and Effects

2.1 Computing for Creativity, Problem Solving, Communication, and Innovation 2.2 Equal Access, the Digital Divide, and Accessibility 2.3 Beneficial and Harmful Effects of Computing Innovations

3 Chapter 3: Impacts of Computing: Intellectual Property, Ethics, Privacy, and Security

3.1 Intellectual Property: Copyright, Open Source, and Creative Commons 3.2 Ethical and Unethical Computing Practices and Their Implications 3.3 Privacy, Security, Data Collection, and Local vs. Cloud Storage

4 Chapter 4: Algorithms and Computational Thinking: Abstraction, Decomposition, Number Bases, and Representation

4.1 Abstraction and Abstraction Hierarchies 4.2 Decomposition, Pattern Recognition, and Developing Algorithms 4.3 Number Bases: Binary, Octal, Decimal, and Hexadecimal 4.4 Algorithm Formats: Natural Language, Flowcharts, Pseudocode, and Tracing

5 Chapter 5: Algorithms: Efficiency, Limits of Computing, and Randomization

5.1 Algorithm Efficiency: Linear, Quadratic, Exponential, and Logarithmic Growth 5.2 Limits of Computing: Unsolvable Problems, Intractability, and Heuristics 5.3 Randomization, Random vs. Pseudorandom Numbers, and Scaling to a Range

6 Chapter 6: Algorithms: Searching, Sorting, and Recursion

6.1 Searching Algorithms: Linear Search and Binary Search 6.2 Sorting Algorithms: Tracing, Comparisons, Correctness, and Efficiency 6.3 Recursion: Base Cases, Tracing, Errors, and Iterative Equivalents

7 Chapter 7: Programming: Variables, Data Types, Strings, and Expressions

7.1 Variables, Data Types, and Type Conversion 7.2 Strings and String Operations 7.3 Operators, Precedence, Expressions, and Formulas 7.4 Boolean Expressions, Truth Tables, and Boolean Algebra

8 Chapter 8: Programming: Selection, Iteration, and Writing Code

8.1 Sequence and Selection: if, else, Chained and Nested Conditions 8.2 Iteration: for, while, do … while, and repeat … until Loops 8.3 Reading, Completing, and Modifying Code

9 Chapter 9: Programming: Procedures, Arrays, and Data Structures

9.1 Procedures, Parameters, Return Values, Nested Calls, and Scope 9.2 Arrays, Lists, and Two-Dimensional Arrays 9.3 Stacks, Queues, and Dictionaries (Maps)

10 Chapter 10: Programming: Correctness, Errors, Testing, and Code Quality

10.1 Program Correctness: Preconditions, Postconditions, Invariants, and Testing vs. Proof 10.2 Error Types and Debugging Techniques 10.3 Choosing Useful Test Cases: Boundaries, Partitions, Coverage, and Regression 10.4 Extensibility, Modifiability, and Reusability: Constants and Parameterization 10.5 Documentation, Code Reviews, Peer Feedback, and End-User Feedback

11 Chapter 11: Programming: Events, Usability, Input Validation, and APIs

11.1 Event-Driven Programming, Asynchronous Events, and Concurrency 11.2 Usability, Meaningful Error Messages, and Input Validation vs. Verification 11.3 Libraries and APIs: Reading Definitions, Making Calls, and Weighing Trade-offs

12 Chapter 12: Programming: Languages, Tools, Paradigms, and Object-Oriented Design

12.1 Low- and High-Level Languages, Compilers and Interpreters, and IDEs 12.2 Programming Paradigms: Procedural, Object-Oriented, and Others 12.3 Classes, Objects, Instance Variables, Methods, and Encapsulation 12.4 Inheritance, Polymorphism, and Overloading vs. Overriding

13 Chapter 13: Data: Bits, Encoding, Compression, and Encryption

13.1 Bits and Bytes: Why Binary, Storage Calculations, and Signed Integers 13.2 Encoding Text, Images, and Sound 13.3 Lossless and Lossy Compression: Run-Length Encoding, Huffman Coding, and Media Formats 13.4 Encoding vs. Encryption, Symmetric and Public-Key Encryption, and Their Trade-offs

14 Chapter 14: Data: Analysis Tools, Simulation, Storage, and Collection

14.1 Analyzing Data with Spreadsheets: Cleaning, Transforming, and Visualizing 14.2 Simulation and Modeling 14.3 Files, Databases, and Storage Requirements: Scale, Redundancy, and Backup 14.4 Collecting, Aggregating, and Generating Data: Public Data Sets, Surveys, Sensors, and Crowdsourcing

15 Chapter 15: Computing Systems: Hardware, Operating Systems, and Computing Environments

15.1 Hardware Components and the Fetch–Decode–Execute Cycle 15.2 Operating Systems, Software Components, and Resource Issues 15.3 Embedded Systems, the Internet of Things, and Types of Computing Systems 15.4 Local, Network, and Cloud Computing and Storage; How Binary Data Are Stored

16 Chapter 16: Networks, the Internet, the Web, and Cybersecurity

16.1 Network Types and Wired and Wireless Communication 16.2 Network Hardware and Layered Network Models (OSI and TCP/IP) 16.3 Network Performance: Bandwidth, Latency, Load, and Estimating Needs 16.4 How the Internet Works: Protocols, IP Addressing, DNS, URLs, and Reliability 16.5 The Web: HTTP, HTML and Markup Languages, Browsers, Servers, and Clients 16.6 Cybersecurity: The Five Pillars, Strong Passwords, Security Strategies, and Trade-offs

5.3 Randomization, Random vs. Pseudorandom Numbers, and Scaling to a Range

Key Takeaways Explain This Topic AI

A pseudorandom number generator is a deterministic algorithm: the same seed always produces the same sequence, which makes programs reproducible but predictable.

True random numbers come from unpredictable physical processes, such as electrical noise, and are used where unpredictability is critical.

Security uses such as passwords, keys, and session tokens need a cryptographically secure generator, not an ordinary pseudorandom generator.

If random ( ) returns a value r with 0.0 ≤ r < 1.0, then floor ( r * ( high − low + 1 ) ) + low gives an integer from low to high inclusive, each equally likely.

Randomization is appropriate for simulations, games, fair sampling and assignment, randomized algorithms such as a random quicksort pivot, and generating test data.

Last updated: September 2026

What this competency asks

ETS asks you to be familiar with the use of randomization in computing :

Identify appropriate uses of randomization in a variety of applications.

Identify the difference between random and pseudorandom numbers.

The discussion questions add a practical skill: transforming a random number generator to fit a specific range .

Where randomization is appropriate

Use Why randomness helps Example

Simulation (Monte Carlo) Models uncertain events and estimates probabilities by running many trials Simulating customer arrivals to size a checkout line

Games Unpredictability makes games fair and interesting Dice rolls, card shuffles, enemy behavior

Sampling Every member has an equal chance, which reduces selection bias Choosing 100 students at random for a survey

Fair assignment Removes the chooser's bias Randomly assigning lab partners; random treatment groups in experiments

Randomized algorithms Avoids a consistently bad worst case A random pivot makes quicksort's O(n²) case very unlikely on sorted input

  • Testing Generates many varied inputs automatically Random test data; "fuzz testing" with random inputs
  • Security Values must be unguessable Encryption keys, password salts, session tokens
  • Procedural content Creates variety without hand-authoring Terrain or levels in a game

Randomness is not appropriate when results must be exactly reproducible and fair in a deterministic sense, such as computing grades or bank balances. It is also inappropriate when the "random" choice would hide a bias, for example "randomly" checking only the first few records.

Random vs. pseudorandom

True random numbers come from physically unpredictable processes, such as electrical (thermal) noise, radioactive decay, or other hardware noise sources. Future values cannot be predicted even with complete knowledge of past values.

Pseudorandom numbers are produced by a deterministic algorithm , a pseudorandom number generator (PRNG). A PRNG starts from a seed and applies a formula to produce each next value. The output passes statistical tests for randomness, but:

The same seed always produces the same sequence . That is useful for reproducible simulations and debugging.

The sequence eventually repeats (it has a period).

Someone who knows the algorithm and the state can predict future values.

A tiny pseudorandom generator

A classic PRNG is the linear congruential generator : next = (a × current + c) % m. With a = 5, c = 3, m = 16, and seed 7:

  • Step Calculation Value
  • seed — 7
  • 1 (5 × 7 + 3) % 16 = 38 % 16 6
  • 2 (5 × 6 + 3) % 16 = 33 % 16 1
  • 3 (5 × 1 + 3) % 16 = 8 % 16 8
  • 4 (5 × 8 + 3) % 16 = 43 % 16 11
  • 5 (5 × 11 + 3) % 16 = 58 % 16 10

The values look scattered, but anyone who knows the formula and the seed can reproduce them exactly. Real generators use much larger numbers and better formulas, but the principle is the same.

Security needs a stronger generator

Because ordinary PRNGs are predictable, security-sensitive values such as passwords, encryption keys, salts, and session tokens must come from a cryptographically secure random generator. Such a generator is seeded from unpredictable system sources of randomness (entropy) and designed so that its outputs cannot be predicted. Seeding a generator with the current time is a classic mistake, because an attacker can guess the seed.

Transforming a generator to a range

Assume a library procedure random ( ) returns a double r with 0.0 ≤ r < 1.0 , and floor ( x ) returns the greatest integer less than or equal to x. // returns an integer from low to high, inclusive

  • int randomBetween ( int low, int high )
  • double r ← random ( )
  • return floor ( r * ( high - low + 1 ) ) + low
  • end randomBetween

Why it works, for a six-sided die (low = 1, high = 6):

high - low + 1 is 6, the number of possible values .

r * 6 falls in [0, 6), so its floor is 0, 1, 2, 3, 4, or 5, each with equal probability.

Adding low shifts the range to 1–6.

  • Common mistake Result
  • Using high - low instead of high - low + 1 high can never occur (a die that never rolls 6)
  • Forgetting + low Range starts at 0 instead of low

Rounding instead of flooring, such as round ( r * 5 ) + 1 All six values occur, but 1 and 6 occur only half as often as the others

Taking a large random integer % n when the generator's range is not a multiple of n Small values become slightly more likely than large ones

Other transformations follow the same logic. A generator that returns 1–6 becomes 0–5 by subtracting 1. A random even number from 0 to 10 is 2 * randomBetween ( 0, 5 ) . A random true or false is random ( ) < 0.5 , and a 30% chance is random ( ) < 0.3 .

Randomness in simulations

Randomized simulations estimate rather than compute exactly. Flip a simulated fair coin 10 times and you might see 7 heads. Flip it 10,000 times and the proportion of heads will almost always be very close to 0.5. More trials give more reliable estimates , but each run can still differ unless you fix the seed. Section 14.2 covers simulation and modeling in more depth.