Answer the question
In order to leave comments, you need to log in
What determines the correlation in the loss of random numbers?
In short, I wrote a program in php. Here is her code.
<?
$one = 0;
$two = 0;
for ($i=0; $i < 10000; $i++) {
$a = rand(1,2);
if ($a == 1) {
$one++;
} else {
$two++;
}
}
echo "1:".$one." | 2: ".$two;
?>
1:5082 | 2:4918
1:5052 | 2:4948
1:5033 | 2:4967
1:4945 | 2:5055
1:5010 | 2:4990
Answer the question
In order to leave comments, you need to log in
What you call correlation is better called scatter.
The distribution of the random variable "number of occurrences of units" is described by the binomial distribution .
The mathematical expectation of such a value is n * p, in your case n=10000, p=0.5, it turns out that on average one will appear 5000 times in a series of 10000 trials.
The spread can be estimated by calculating the standard deviation. For the binomial distribution, it is equal to sqrt(n*p*(1-p)), in your case it turns out 50. The rule of three sigma in this case should apply, so with a probability of 68% the average value of the "number of occurrences of ones" will be different from 5000 no more than 50, and with a 99% probability no more than 150. This agrees with the numbers you got in your experiment.
All this is explained by the fact that rand returns not a random number, but a pseudo-random number. PHP implements one of the pseudo-random number generators ( PRNG ). And the desired behavior is inherent in real random numbers.
The simplest toy PRNG might look like this
var next = 0;
for(;;){
next = (next*9 + 3) % 256;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question