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


Messages In This Thread
Random isn't very random at all! - by Weirdosport - 05.06.2009, 15:34
Re: Random isn't very random at all! - by OmeRinG - 05.06.2009, 16:31
Re: Random isn't very random at all! - by Weirdosport - 05.06.2009, 17:26
Re: Random isn't very random at all! - by samgreen - 05.06.2009, 17:39

Forum Jump:


Users browsing this thread: 1 Guest(s)