A Good and SIMPLE Measure of Randomness
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Randomness is a fundamental concept with far-reaching implications across fields like mathematics, cryptography, computer science, and statistical inference. Measuring randomness in a way that is both simple and effective is crucial for ensuring the integrity of data-driven processes and systems.
Understanding Randomness
Randomness can be best understood as the lack of pattern or predictability in a set of events. While chaos is often associated with randomness, randomness is not entirely about disorder. In fact, true randomness means that each event in a sequence is independent of others.
Types of Randomness
- True Randomness: Derived from physical phenomena such as radioactive decay.
- Pseudo-Randomness: Generated by algorithms that mimic randomness based on initial seed values.
The Importance of Measuring Randomness
Accurately measuring randomness is essential for applications such as:
• Cryptography: Secure systems rely on the unpredictable nature of cryptographic keys. • Simulations: Random inputs ensure varied outcomes in Monte Carlo simulations. • Statistical Sampling: Random samples help in generating trustworthy statistical insights.
A Simple Measure of Randomness: Chi-Square Test
One effective and straightforward measure to determine the randomness of a dataset is the Chi-Square Test. It's a statistical method that evaluates the divergence between observed and expected frequencies.
Technical Explanation
The Chi-Square statistic is calculated as follows:
Where: • is the observed frequency. • is the expected frequency.
Steps in Using the Chi-Square Test for Randomness
- Define Categories: Segment the data into categories or bins.
- Calculate Expected Frequency: Under the assumption of uniform distribution, every category will have the same expected frequency.
- Compare Frequencies: Use the Chi-Square statistic formula to compare.
- Evaluate: Compare the Chi-Square statistic against a critical value from the Chi-Square distribution table to determine randomness.
Example
Suppose you roll a fair six-sided die 60 times. The expected frequency for each side (assuming randomness) is 10. Let's say the observed counts are:
• Side 1: 11 • Side 2: 9 • Side 3: 8 • Side 4: 10 • Side 5: 12 • Side 6: 10
The Chi-Square statistic is calculated as:
Calculating each term and summing gives:
With 5 degrees of freedom (since there are 6 sides), you would compare 1 against the critical value from a Chi-Square distribution table.
Summary Table
| Parameter | Description |
| Observed Value | Count of occurrences in each bin during the experiment. |
| Expected Value | Count assuming a perfect uniform distribution, e.g., total trials divided by bin count. |
| Chi-Square | Sum of the squared difference between observed and expected, scaled by the expected value. |
| Degrees of Freedom | Number of categories minus one. |
| Critical Value | Reference threshold that should cross for the result to be significant. |
Enhanced Understanding: Entropy
Another measure of randomness is entropy, especially in information theory. Shannon defined entropy as a measure of uncertainty, calculated as:
Where is the probability of the outcome . Higher entropy indicates more randomness.
Conclusion
The measure of randomness is a topic of significant importance with practical implications. While the Chi-Square test provides a simple yet powerful statistical approach, other methods such as entropy offer additional insights. Depending on the context and complexity of the data, various metrics can be used to understand and validate randomness, crucial for ensuring the robustness of systems that depend on random processes.
Related reading
- A remote access exception in DolphinDB,Can''t find the object with name loadTable(''dfs//zctestDB'',''trainInfoTable'')
- A simple explanation of Naive Bayes Classification
- A simple explanation of Naive Bayes Classification
- A simple explanation of Random Forest
- A linear-time algorithm to find any vertex of a polygon visible from other vertex
- A Onlogn algorithm to find the segment among nn segments with the lowest slope
- About accuracy in recommendation system
- Accessing a File from Distributed Cache in Pig UDF Java class, Amazon EMR

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 courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.