SlideShare a Scribd company logo
TESTING NUMBERS FOR RANDOMNESS
CHI SQUARE TEST
SUBMITTED TO:
MS. PRIYANKA
UIET, CSE
PANJAB UNIVERSITY, CHANDIGARH
PRESENTATION BY:
UE213070 RACHIT SHARMA
UE213071 RAGHAV GOEL
UE213072 RAHUL RAJ
UE213073 RIDHAM GUPTA
RECAP:
Up until now what we have studied is:-
● What are random numbers?
● Importance of Random numbers
● Pseudo Random numbers
● Different methods to generate Random numbers:-
○ Mid-square random number generator
○ Residue method
○ Arithmetic Congruential Generator
INTRODUCTION
In this module we will learn about how to test whether a given a sequence of numbers is random or not. For this we
will firstly refer to the two important properties of random numbers which are:
● Uniformity- This means that the method from which random number is generated, every number has an equal
chance of occurrence.
● Independence- This means that there is no correlation between the numbers present in the sequence.
Eg. 0,2,4,6,8
The given above sequence is uniform but it is not independent because as we can see that the given sequence is
of even numbers and we can predict the next number.
So for testing that whether a given sequence of numbers are random or not we have to check these two properties. So,
test for uniformity is performed to validate a random number generator. These tests compare the generated random
numbers with the theoretical uniform distribution. The two uniformity/frequency test we perform are:-
● Kolmogorv-Smirnov Test
● Chi-Square Test
For testing independence we perform chi square test for serial autocorrelation.
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
Testing Numbers for Randomness Chi Square test
CHI-SQUARED TEST
• The Chi-Squared Test uses the sample statistic
Where Oi is the observed number in the ith class, Ei is the expected number in the ith class and n is
the number of classes. For the uniform distribution, Ei, the expected number in each class is given by
For equally spaced classes, where N is the total number of observations. It can be shown that the
sampling distribution of x2 is approximately the chi-square distribution with n-1 degree of freedom.
• This test involves the classification of 500 random numbers b/w 0 and 1 into 10 equal
intervals, that is numbers less than or equal to 0.1 less than or equal to 0.2, 0.3, ...., 1.0.
• A bar chart or histogram can than be plotted to illustrate the uniformity of distribution, If
the 500 numbers were distributed among the 10 classes, with perfect uniformity, all bars
will be of equal length of 50 numbers.
• Chi-square is a characteristic of the distribution which is a measure of its randomness.
• The statistic Chi-Square is computed by subtracting the number of random numbers in
each class from the expected number(that is 50), squaring the difference, adding the
squares for the ten classes, and dividing the sum by the expectation(50).
• For example, if 47, 49, 55, 54, 46, 53, 51, 43, 46 and 54 are the numbers in 10 classes.
Then their differences from 50 are 3, 1, 5, 4, 4, 3, 1, 7, 4, and 4; and sum of the
squares of differences is 9 + 1 + 25 + 16 + 16 + 9 + 1 + 49 + 16 + 16 = 158
Chi- square = 158/50 = 3.16
• There are tables of Chi-square that will tell us about the goodness of the results. The
acceptable value of Chi-square will depend upon the degrees of freedom which are
one less than the number of classes, and the level of confidence we wish to place in
our results.
• In the present case, since there are 10 classes in which we have divided the random
numbers, there are 9 degrees of freedom. At 95% confidence level the acceptable
value of Chi-square for 9 degrees of freedom is 16.919 .
• This means that when the value of Chi-square is less than or equal to 16.9, there are
only 5/chances out of 100 that our results are wrong.
Chi-Squared Test can be employed to compare different sets of random numbers or
different random number generators. For each set of random numbers the statistics Chi-
square is computed The one with smaller value of Chi-square is more uniformly
distributed
CHI-SQUARED TEST - UNIFORMITY- RANDOM NUMBERS
CHI-SQUARED TEST - UNIFORMITY- RANDOM NUMBERS
CHI-SQUARED TEST - UNIFORMITY- RANDOM NUMBERS
CHI-SQUARED TEST – TESTING FOR
AUTOCORRELATION
• The uniformity test of random numbers is only a necessary test for randomness, not a sufficient one. A
sequence of numbers may be perfectly uniform, and still not random.
• For example, the sequence .1, .2, .3, .4., .1, .2, .3, ....., would give a perfectly uniform distribution with
the chi-square value as zero. But the sequence can by no means be regarded as random. The numbers
are not independent, as the occurrence of one number say .3 decides the next, which is to be .4 etc.
This defect is called 'serial autocorrelation of adjacent pairs of indes the ne
• The Chi-Squared test for serial autocorrelation makes use of a 10 x 10 matrix (checker board). The 10
classes described in the uniformity test are represented both along the rows and columns. If the
classes are to be represented on a bar chart, 100 bars, one for each cell of the matrix, will be required.
To reduce the number of groups, instead of 10, random numbers are divided into smaller number of
classes as 3, or 4. Three classes will be: less than or equal to 0.33, less than or equal to 0.67 and less
than or equal to 1.0. With three classes in rows and three in columns, there will be 9 cells
Let us consider the following random numbers :
These 73 random numbers giving 72 pairs, are grouped into 9 classes with expectation
of 8 in each group.
Chi-square = 24/8
= 3.0
• The counts in different classes have been determined by taking the pairs of random
numbers.
• Pair .49 and .95 falls in class R1 <= 67 and R2 <= 1.0 Then the next pair is .95 and .82
which falls in class R1 <= 1.0 and R2 <= 1.0, Pair .82 and .19 falls in class R1 <= 1.0 and
R2 <= 0.33 and so on.
• Since the total number of pairs in 72, one less than the number of random numbers,
the expectation is 8, that is 8 in each class. Then squares of differences (frequency -
expectation) are determined and their sum is obtained, which on division by
expectation gives the value of Chi-square as 3.0.
• In this case there are two variables R1 and R2 and hence the degrees of freedom are
nine minus two that is seven. The criterion value of x² (chi-square) for seven degrees
of freedom at 95% confidence level is 14.067. The value of Chi-square obtained for
the given set of random number is well within the acceptable limit, and hence, they
are not serially autocorrelated.System
EXAMPLE. GIVEN BELOW IS A SEQUENCE OF RANDOM
NUMBERS. PERFORM THE CHI- SQUARED TESTS TO CHECK
THE NUMBERS FOR UNIFORM DISTRIBUTION AND SERIAL
AUTOCORRELATION
• Uniformity Test
i. For checking the random numbers for the uniformity, we will divide these in 10 class
and take 90 random numbers to have the expected value in each class as 9.
ii. There are ten classes and one variable, giving 9 degrees of freedom. For 9 degrees of
freedom at 95% confidence level, the acceptable value of x^{2} is up to 16.9. Our
value of x^{2} is well within the acceptable limit and hence, the random numbers in
the given sequence are uniformly distributed
• Chi-Squared Test for Autocorrelation
i. For this test, the overlapping pairs of random numbers are to be taken. Taking three
classes; 33; 34 to 67 and 68 to 100 for each random number in the pair, the number of
pairs in each is is obtained as follows. Since there are 9 classes, the expectation value is
10
The criterion value of x² for 7 degrees of freedom at 95% confidence level is 14.1, which is
less than the value we have obtained for the given sequence. Thus, the given sequence of
random numbers is serially autocorrelated at 95% confidence level.

More Related Content

PPTX
Exponential probability distribution
PPTX
Properties of estimators (blue)
PDF
LPP, Duality and Game Theory
PPTX
Linear and Logistics Regression
PPTX
Solving linear programming model by simplex method
PPT
Queuing theory
PDF
Normal distribution
PPTX
Geometric Distribution
Exponential probability distribution
Properties of estimators (blue)
LPP, Duality and Game Theory
Linear and Logistics Regression
Solving linear programming model by simplex method
Queuing theory
Normal distribution
Geometric Distribution

What's hot (20)

PPSX
Graphical method
PPTX
Skewness,Moments & kurtosis
PPTX
Queuing Theory
PPTX
Hypergeometric probability distribution
PDF
Gomory's cutting plane method
PPTX
graphical method
PPTX
Poisson distribution presentation
PPTX
Multinomial distribution
PPTX
Chap05 continuous random variables and probability distributions
PPTX
Simulation in Operation Research
PPTX
Geometric probability distribution
PPTX
Game theory
PDF
Transportation Problem- Initial Basic Feasible Solution
DOCX
Autocorrelation
PPT
Skewness.ppt
PPTX
Test of significance of large samples
PPT
Spline Interpolation
PDF
Theory of probability
PDF
Fourier series and transforms
DOC
Grandes Mestres das Ciências Sociais
Graphical method
Skewness,Moments & kurtosis
Queuing Theory
Hypergeometric probability distribution
Gomory's cutting plane method
graphical method
Poisson distribution presentation
Multinomial distribution
Chap05 continuous random variables and probability distributions
Simulation in Operation Research
Geometric probability distribution
Game theory
Transportation Problem- Initial Basic Feasible Solution
Autocorrelation
Skewness.ppt
Test of significance of large samples
Spline Interpolation
Theory of probability
Fourier series and transforms
Grandes Mestres das Ciências Sociais
Ad

Similar to Testing Numbers for Randomness Chi Square test (20)

PPTX
Statistical tests
PPTX
MT6702 Unit 2 Random Number Generation
PPTX
Chi square test
PPTX
CHI SQUARE DISTRIBUTIONdjfnbefklwfwpfioaekf.pptx
PPT
Q3W2_Chi-Square Distribution (1Q3W2_Chi-Square Distribution (1).ppt).ppt
PPT
Q3W2_Chi-Square Distribution - Copy (1).ppt
PPTX
Chi square test
PPTX
Chi square test
PPTX
Unit 3 random number generation, random-variate generation
PPTX
Chi square
PPTX
chi-Square. test-
PPTX
Chi-square test.pptx
PPTX
The Chi-Square Statistic: Tests for Goodness of Fit and Independence
PPTX
Random number generation
PPT
chi-squaretest-170826142554.ppt
PPT
Chi square mahmoud
DOCX
PPTX
Chi-square-Distribution: Introduction & Applications
PDF
Stat 130 chi-square goodnes-of-fit test
Statistical tests
MT6702 Unit 2 Random Number Generation
Chi square test
CHI SQUARE DISTRIBUTIONdjfnbefklwfwpfioaekf.pptx
Q3W2_Chi-Square Distribution (1Q3W2_Chi-Square Distribution (1).ppt).ppt
Q3W2_Chi-Square Distribution - Copy (1).ppt
Chi square test
Chi square test
Unit 3 random number generation, random-variate generation
Chi square
chi-Square. test-
Chi-square test.pptx
The Chi-Square Statistic: Tests for Goodness of Fit and Independence
Random number generation
chi-squaretest-170826142554.ppt
Chi square mahmoud
Chi-square-Distribution: Introduction & Applications
Stat 130 chi-square goodnes-of-fit test
Ad

Recently uploaded (20)

PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPT
Project quality management in manufacturing
PDF
Well-logging-methods_new................
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Sustainable Sites - Green Building Construction
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
composite construction of structures.pdf
DOCX
573137875-Attendance-Management-System-original
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
OOP with Java - Java Introduction (Basics)
UNIT 4 Total Quality Management .pptx
Lecture Notes Electrical Wiring System Components
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Structs to JSON How Go Powers REST APIs.pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Project quality management in manufacturing
Well-logging-methods_new................
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Sustainable Sites - Green Building Construction
CYBER-CRIMES AND SECURITY A guide to understanding
composite construction of structures.pdf
573137875-Attendance-Management-System-original
UNIT-1 - COAL BASED THERMAL POWER PLANTS
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Model Code of Practice - Construction Work - 21102022 .pdf
OOP with Java - Java Introduction (Basics)

Testing Numbers for Randomness Chi Square test

  • 1. TESTING NUMBERS FOR RANDOMNESS CHI SQUARE TEST SUBMITTED TO: MS. PRIYANKA UIET, CSE PANJAB UNIVERSITY, CHANDIGARH PRESENTATION BY: UE213070 RACHIT SHARMA UE213071 RAGHAV GOEL UE213072 RAHUL RAJ UE213073 RIDHAM GUPTA
  • 2. RECAP: Up until now what we have studied is:- ● What are random numbers? ● Importance of Random numbers ● Pseudo Random numbers ● Different methods to generate Random numbers:- ○ Mid-square random number generator ○ Residue method ○ Arithmetic Congruential Generator
  • 3. INTRODUCTION In this module we will learn about how to test whether a given a sequence of numbers is random or not. For this we will firstly refer to the two important properties of random numbers which are: ● Uniformity- This means that the method from which random number is generated, every number has an equal chance of occurrence. ● Independence- This means that there is no correlation between the numbers present in the sequence. Eg. 0,2,4,6,8 The given above sequence is uniform but it is not independent because as we can see that the given sequence is of even numbers and we can predict the next number.
  • 4. So for testing that whether a given sequence of numbers are random or not we have to check these two properties. So, test for uniformity is performed to validate a random number generator. These tests compare the generated random numbers with the theoretical uniform distribution. The two uniformity/frequency test we perform are:- ● Kolmogorv-Smirnov Test ● Chi-Square Test For testing independence we perform chi square test for serial autocorrelation.
  • 17. CHI-SQUARED TEST • The Chi-Squared Test uses the sample statistic Where Oi is the observed number in the ith class, Ei is the expected number in the ith class and n is the number of classes. For the uniform distribution, Ei, the expected number in each class is given by For equally spaced classes, where N is the total number of observations. It can be shown that the sampling distribution of x2 is approximately the chi-square distribution with n-1 degree of freedom.
  • 18. • This test involves the classification of 500 random numbers b/w 0 and 1 into 10 equal intervals, that is numbers less than or equal to 0.1 less than or equal to 0.2, 0.3, ...., 1.0. • A bar chart or histogram can than be plotted to illustrate the uniformity of distribution, If the 500 numbers were distributed among the 10 classes, with perfect uniformity, all bars will be of equal length of 50 numbers. • Chi-square is a characteristic of the distribution which is a measure of its randomness. • The statistic Chi-Square is computed by subtracting the number of random numbers in each class from the expected number(that is 50), squaring the difference, adding the squares for the ten classes, and dividing the sum by the expectation(50). • For example, if 47, 49, 55, 54, 46, 53, 51, 43, 46 and 54 are the numbers in 10 classes. Then their differences from 50 are 3, 1, 5, 4, 4, 3, 1, 7, 4, and 4; and sum of the squares of differences is 9 + 1 + 25 + 16 + 16 + 9 + 1 + 49 + 16 + 16 = 158 Chi- square = 158/50 = 3.16
  • 19. • There are tables of Chi-square that will tell us about the goodness of the results. The acceptable value of Chi-square will depend upon the degrees of freedom which are one less than the number of classes, and the level of confidence we wish to place in our results. • In the present case, since there are 10 classes in which we have divided the random numbers, there are 9 degrees of freedom. At 95% confidence level the acceptable value of Chi-square for 9 degrees of freedom is 16.919 . • This means that when the value of Chi-square is less than or equal to 16.9, there are only 5/chances out of 100 that our results are wrong. Chi-Squared Test can be employed to compare different sets of random numbers or different random number generators. For each set of random numbers the statistics Chi- square is computed The one with smaller value of Chi-square is more uniformly distributed
  • 20. CHI-SQUARED TEST - UNIFORMITY- RANDOM NUMBERS
  • 21. CHI-SQUARED TEST - UNIFORMITY- RANDOM NUMBERS
  • 22. CHI-SQUARED TEST - UNIFORMITY- RANDOM NUMBERS
  • 23. CHI-SQUARED TEST – TESTING FOR AUTOCORRELATION • The uniformity test of random numbers is only a necessary test for randomness, not a sufficient one. A sequence of numbers may be perfectly uniform, and still not random. • For example, the sequence .1, .2, .3, .4., .1, .2, .3, ....., would give a perfectly uniform distribution with the chi-square value as zero. But the sequence can by no means be regarded as random. The numbers are not independent, as the occurrence of one number say .3 decides the next, which is to be .4 etc. This defect is called 'serial autocorrelation of adjacent pairs of indes the ne • The Chi-Squared test for serial autocorrelation makes use of a 10 x 10 matrix (checker board). The 10 classes described in the uniformity test are represented both along the rows and columns. If the classes are to be represented on a bar chart, 100 bars, one for each cell of the matrix, will be required. To reduce the number of groups, instead of 10, random numbers are divided into smaller number of classes as 3, or 4. Three classes will be: less than or equal to 0.33, less than or equal to 0.67 and less than or equal to 1.0. With three classes in rows and three in columns, there will be 9 cells
  • 24. Let us consider the following random numbers : These 73 random numbers giving 72 pairs, are grouped into 9 classes with expectation of 8 in each group. Chi-square = 24/8 = 3.0
  • 25. • The counts in different classes have been determined by taking the pairs of random numbers. • Pair .49 and .95 falls in class R1 <= 67 and R2 <= 1.0 Then the next pair is .95 and .82 which falls in class R1 <= 1.0 and R2 <= 1.0, Pair .82 and .19 falls in class R1 <= 1.0 and R2 <= 0.33 and so on. • Since the total number of pairs in 72, one less than the number of random numbers, the expectation is 8, that is 8 in each class. Then squares of differences (frequency - expectation) are determined and their sum is obtained, which on division by expectation gives the value of Chi-square as 3.0. • In this case there are two variables R1 and R2 and hence the degrees of freedom are nine minus two that is seven. The criterion value of x² (chi-square) for seven degrees of freedom at 95% confidence level is 14.067. The value of Chi-square obtained for the given set of random number is well within the acceptable limit, and hence, they are not serially autocorrelated.System
  • 26. EXAMPLE. GIVEN BELOW IS A SEQUENCE OF RANDOM NUMBERS. PERFORM THE CHI- SQUARED TESTS TO CHECK THE NUMBERS FOR UNIFORM DISTRIBUTION AND SERIAL AUTOCORRELATION
  • 27. • Uniformity Test i. For checking the random numbers for the uniformity, we will divide these in 10 class and take 90 random numbers to have the expected value in each class as 9. ii. There are ten classes and one variable, giving 9 degrees of freedom. For 9 degrees of freedom at 95% confidence level, the acceptable value of x^{2} is up to 16.9. Our value of x^{2} is well within the acceptable limit and hence, the random numbers in the given sequence are uniformly distributed
  • 28. • Chi-Squared Test for Autocorrelation i. For this test, the overlapping pairs of random numbers are to be taken. Taking three classes; 33; 34 to 67 and 68 to 100 for each random number in the pair, the number of pairs in each is is obtained as follows. Since there are 9 classes, the expectation value is 10 The criterion value of x² for 7 degrees of freedom at 95% confidence level is 14.1, which is less than the value we have obtained for the given sequence. Thus, the given sequence of random numbers is serially autocorrelated at 95% confidence level.