Random isn't very random at all!
#1

Before I start, this isn't me begging for help, this is me discussing scripting. I am not necessarily looking for an answer.

I know that for a computer generating random numbers isn't exactly easy, and that they have to use pseudo random number generators to accomplish it. There are very few processes that are genuinely random in the world (like radioactive decay).

But I never thought that the random feature in PAWN would be so .. well. un-random. I thought I'd construct a little test "jig" to see how it faired, and was surprised. I asked it to generate a random number from 0-9 1 billion times, and print the results. Here's what happened:

Код:
[16:14:26] 1 - 99998144
[16:14:26] 2 - 100008336
[16:14:26] 3 - 99990403
[16:14:26] 4 - 100006435
[16:14:26] 5 - 100006398
[16:14:26] 6 - 99993997
[16:14:26] 7 - 99997709
[16:14:26] 8 - 99997529
[16:14:26] 9 - 100007402
[16:14:26] 10 - 99993647
No doing some quick maths, you'd realise that from 1 billion supposedly random numbers, the range is only 17933.

I then tried it with 2 categories and 10,000 tests and ended up with an exact 5000 - 5000 split...

I realise on a small scale this isn't a big deal but it just doesn't seem random enough!

If you'd like to know how I tested it:

pawn Код:
#include <a_samp>

#define CALLS 100
#define CATERGORIES 20

new Random[CATERGORIES];

public OnFilterScriptInit()
{
    for(new i; i < CALLS; i++)
    {
        Random[random(CATERGORIES)]++;
    }
    printf("\n%d Random Numbers split %d ways:\n", CALLS, CATERGORIES);
    for(new i; i < CATERGORIES; i++)
    {
      printf("%d - %d", i + 1, Random[i]);
    }
    print(" ");
    return 1;
}
Calls is how many random numbers you want, Catergories is sort of self explanatory.. Some of the print lines are purely decorative.. Please try this for yourself and report back any findings you have that disagree with my own.
Reply
#2

Well I think that's because an integer can't hold such a big number as 2 billion....
not sure though
Reply
#3

Quote:
Originally Posted by OmeRinG
Well I think that's because an integer can't hold such a big number as 2 billion....
not sure though
The integer limit is over 2.1 billion (for some programs like Java) and i'm only dealing with 1 billion. And that wouldn't effect the range of the results, only the quantity I got =/
Reply
#4

The Pawn manual has this to say about its random number generator:

Quote:
Originally Posted by Pawn-lang.pdf
The standard random number generator of pawn is likely a linear congruential pseudo-random number generator with a range and a period of 231. Linear congruential pseudo-random number generators suffer from serial correlation (especially in the low bits) and it is unsuitable for applications that require high-quality random numbers.
Of course, serial correlation is the correlation of a variable with itself over successive time intervals. Unfortunately the Pawn language was just not designed with high quality random numbers in mind. In most other languages this problem is rarely noticed because we can seed the random number generator with the current time. We should stop testing between each other, and write a higher quality random number generator.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)