08-24-2016, 09:02 PM
(This post was last modified: 08-24-2016, 09:02 PM by Soldier . . ..)
I have completely lost the faith in the randomness of the random generator of CoD a long time a go already.
Here a better algorithm to generate a random value.
You can try to implement this one and use it instead of the one of CoD.
If you have time and like to do it of course
examples:
Here a better algorithm to generate a random value.
You can try to implement this one and use it instead of the one of CoD.
If you have time and like to do it of course
Code:
static unsigned int m_z = 12434;
static unsigned int m_w = 33254;
// random generator -----------------------------------------------
unsigned int random (unsigned int iSize)
{
static unsigned int iRandOld = 0;
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
if (iRandOld == (((m_z << 16) + m_w) % iSize))
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
}
iRandOld = ((m_z << 16) + m_w) % iSize;
return (iRandOld);
}
examples:
Quote:number of random generator function calls checked: 2000000
number of unique values that can be created: 4
first 2 numbers match to start: 156345
first 3 numbers match to start: 48804
first 4 numbers match to start: 15167
first 5 numbers match to start: 4740
first 2 numbers are equal: 124969, 6.25%
first 3 numbers are equal: 7858, 0.39%
first and third are equal: 593289, 29.66%
0 = 499519, 24.98%
1 = 500641, 25.03%
2 = 499703, 24.99%
3 = 500137, 25.01%
Quote:number of random generator function calls checked: 2000000
number of unique values that can be created: 5
first 2 numbers match to start: 96245
first 3 numbers match to start: 23215
first 4 numbers match to start: 5652
first 5 numbers match to start: 1361
first 2 numbers are equal: 79299, 3.96%
first 3 numbers are equal: 3070, 0.15%
first and third are equal: 464242, 23.21%
0 = 399637, 19.98%
1 = 400140, 20.01%
2 = 400008, 20.00%
3 = 400391, 20.02%
4 = 399824, 19.99%
Quote:number of random generator function calls checked: 4000000
number of unique values that can be created: 7
first 2 numbers match to start: 93256
first 3 numbers match to start: 15404
first 4 numbers match to start: 2533
first 5 numbers match to start: 414
first 2 numbers are equal: 81555, 2.04%
first 3 numbers are equal: 1741, 0.04%
first and third are equal: 641392, 16.03%
0 = 571390, 14.28%
1 = 571488, 14.29%
2 = 571107, 14.28%
3 = 572189, 14.30%
4 = 571982, 14.30%
5 = 570435, 14.26%
6 = 571409, 14.29%
Quote:number of random generator function calls checked: 4000000
number of unique values that can be created: 21
first 2 numbers match to start: 9555
first 3 numbers match to start: 492
first 4 numbers match to start: 32
first 5 numbers match to start: 3
first 2 numbers are equal: 9047, 0.23%
first 3 numbers are equal: 17, 0.00%
first and third are equal: 198405, 4.96%
0 = 190227, 4.76%
1 = 190142, 4.75%
2 = 190308, 4.76%
3 = 191151, 4.78%
4 = 190740, 4.77%
5 = 189281, 4.73%
6 = 190797, 4.77%
7 = 190227, 4.76%
8 = 190962, 4.77%
9 = 190001, 4.75%
10 = 190175, 4.75%
11 = 190247, 4.76%
12 = 190459, 4.76%
13 = 190224, 4.76%
14 = 191017, 4.78%
15 = 190687, 4.77%
16 = 190621, 4.77%
17 = 190686, 4.77%
18 = 191104, 4.78%
19 = 190438, 4.76%
20 = 190506, 4.76%