Algorithm for calculating probabilities of a number being drawn opening a book
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
Understanding the probability of a number being chosen when you open a book is an intriguing concept involving both randomness and structured probability analysis. This can be approached mathematically by creating relevant algorithms and can also be seen through the lens of probability distribution.
Understanding the Problem
When you open a book to a random page, various factors influence the number/page selection:
- Uniform Distribution: If we assume each page has an equal probability of being picked.
- Book Bias: Physical properties such as the binding might make certain sections more likely to fall open.
- Human Bias: People have tendencies or preferences for certain sections or numerical ranges.
We'll focus on calculating the probabilities assuming a uniform distribution, adding complexity through weight factors, and finally considering real-world imperfections like book bias.
Assumptions
- The number of pages, , is known.
- Each page has an equal probability of being chosen.
- We'll explore both theoretical (ideal) and practical (real-world) scenarios.
Theoretical Model: Uniform Distribution
In a perfect setting, each page number from 1 to has an equal chance of being selected. Under uniform distribution:
This simplistic model presumes no additional human or physical biases.
Example:
For a book with 100 pages (), the probability of opening to page 42 is:
Introducing Weighted Probabilities
Books might have sections with different page quality or people might prefer opening pages with certain content (e.g., illustrations, chapters).
Weight Function
We define a weight function which adjusts the probability for each page . The total probability is normalized to ensure it sums to 1.
Example with Bias:
Consider a book of 5 pages where the central page (page 3) has double the probability of being opened compared to others. for pages 1, 2, 4, 5 is 1, and for page 3 is 2.
• Total Weight • •
Key Points Table
| Page | Probability | Notes | |
| 1 | 1 | 0.167 | Standard page |
| 2 | 1 | 0.167 | Standard page |
| 3 | 2 | 0.333 | Twice as likely due to weight |
| 4 | 1 | 0.167 | Standard page |
| 5 | 1 | 0.167 | Standard page |
Real-World Considerations
Physical Bias
The physical composition of the book might cause certain pages to fall open more easily: • Curvature of the spine causing bias toward middle pages. • Heavily used sections (indexes, prefaces) might flop open easily.
Incorporation of Physical Bias
A refined weight function might consider physical biases, such as centering weights for middle pages or adding higher weights for frequently accessed pages. This results in a more accurate representation of real-world scenarios.
Example:
If the middle of the book (page 50) opens more readily:
• Assign a higher for pages near the center. • Recalculate total probability.
Conclusion and Future Work
Through simple models like uniform distribution to advanced weighted functions considering both bias and real-world behavior, calculating probabilities for book-opening scenarios can be effectively modeled. This can be extended by employing stochastic models or machine learning to dynamically adjust weights based on more comprehensive datasets.
Further studies might explore psychological influences, machine learning prediction models, or how different types of books (e.g., novels vs. textbooks) might exhibit varying probabilistic scenarios.
Related reading
- Algorithm for classifying words for hangman difficulty levels as Easy,Medium, or Hard
- Algorithm for clustering with minimum size constraints
- Algorithm for computing the inverse of a polynomial
- Algorithm for computing the plausibility of a function / Monte Carlo Method
- Algorithm for determining whether a point is inside a 3D mesh
- Algorithm for downsampling array of intervals
- Algorithm for counting common group memberships with big data
- Algorithm for creating a school timetable

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseThere is a whole course on this
Basis Lab has written “Counting Without Listing”, a course that teaches this from the ground up rather than answering the single question. It is a separate product from the same team and the course is free to read.
Read the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.