 |
 |
 |
 |
|
 |
 |
|
 |
 |
|
 |
 |
|
 |
 |
| Author |
Message |
Luth POL Developer
Joined: 30 Jan 2006 Posts: 35
|
Posted: Mon Apr 21, 2008 8:22 pm Post subject: |
|
|
Realize that Random() is NOT an even distribution of numbers. You can do RandomInt(6) ten times in a row and get six 1s, and it is still "random." In fact, if you did have guaranteed statistical evenness then it wouldn't really be random; you'd be able to predict which number would come next. Statistical probabilities are ONLY valid for sufficiently large quantities (hundreds, thousands, or millions of test cases). Anything less is nearly meaningless.
Imagine it like this: There is an infinite sequence of numbers in a list. RandomInt pulls the "next" value and returns it. If you start at the head of the list [0] every time, the sequence will be the same every time. Makes sense, right? Thats where "seeding" comes in. Setting a "seed" is like setting a position in the list to start reading numbers at. Thus you need a random / psuedo-random outside value to seed with.
Phao's fix works because there is a psuedo-random outside value (the time until a "real" randomint call is made) which results in varied previous numbers of times randomint was called, thus psuedo-seeding the random generator. He may be pulling the same sequence of numbers every time, but a random amount of those numbers are discarded before one is accepted.
From a programming point of view, OGs fix is the best; seeding the random number generator with a psuedo-random outside value (in this case, the game clock value [the bigger range the seed, the better]). Its a do-once action that will result in different random sequences (nearly) every time you use it (and it doesn't require another process to keep running ). |
|
 |
|
|
 |
 |
|
 |
 |
|
 |
 |
|
 |
 |
|
 |
 |
|
 |
 |
| Author |
Message |
ncrsn
Joined: 10 Feb 2006 Posts: 168
|
Posted: Wed Apr 23, 2008 6:57 am Post subject: |
|
|
OldnGrey, if your players want predictable randomness and you are willing to give that to them, why are you sticking with random number generator so much?
I didn't test this, but I think it's worth a look.
| Code: |
function Random( number, byref curvalue )
if (curvalue == error)
curvalue := RandomInt(number);
else
curvalue += 1;
endif
if (curvalue >= number - 1)
curvalue := 0;
return 1;
endif
endfunction
|
Usage could be like this.
| Code: |
// Player has a 1/4 chance to get a congratulation message
var curvalue := GetObjProperty(who, "#CongraDice");
if (Random(4, curvalue))
SendSysMessage(who, "Congratulations!");
endif
SetObjProperty(who, "#CongraDice", curvalue);
|
This isn't an ideal script: one would likely integrate the cprop part into (another) function to ease the use. And if repeated this isn't really random at all, so someone could find this even boring.
--
Some years ago I did test the POL's randomness using RandomInt(). I couldn't find the data anymore, so you'll have to take my word for it, but it was surprisingly random when there were 10 000, 100 000 and even million throws. Surprisingly, because I, too, had heard the "POL's random generator sucks!" lines.
I never did test the difference between RandomInt, RandomDiceValue and RandomFloat, because I always thought they were basically the same. |
|
 |
|
|
 |
 |
| Author |
Message |
Luth POL Developer
Joined: 30 Jan 2006 Posts: 35
|
Posted: Wed Apr 23, 2008 8:15 pm Post subject: |
|
|
OG, it sounds like you want non-random returns, then. (And, thus, not a "random problem" ) If you want low-test statistical accuracy, then write your own function:
Create a string "Values":
"00101001100110101110"
function GetFiftyPercent() would look something like:
{
var idx := GetGlobalProp("fiftyIdx");
var val := Values[idx];
SetGlobalProp("fiftyIdx", (idx+1)%(strlen(Values));
return CInt(val);
}
This will give you pure statistical accuracy over a very small (20) trial set. If you make the string long enough that it cant be memorize, but small enough that you can ensure high statistical accuracy over a small trial set, then that should make them happy, right?
(ps: thats psuedo script, dont go copy/pasting and expecting it to work.)
(pps: If you bet on black every time, seeing five reds in a row does not mean that the randomness of physics is broken. ) |
|
 |
|
|
 |
 |
| Author |
Message |
Pierce
Joined: 02 Feb 2006 Posts: 256
|
Posted: Thu Apr 24, 2008 10:50 am Post subject: |
|
|
A few years ago i also thought of a randomint "problem or bug". Therefor i wrote a small textcmd script (.runrandom) to check it. Here the 97 code of it:
| Code: |
use uo;
use os;
use util;
program randomstatistics( who, stopcounter )
var counter := 0;
var temp;
var statisticarray := {0,0,0,0,0,0,0,0,0,0};
while (counter != CInt(stopcounter))
temp := RandomInt(10);
temp += 1;
statisticarray[temp] += 1;
counter += 1;
sleepms(1);
endwhile
SendSysMessage(who, "Statistics: " + statisticarray);
endprogram
|
Sure it can also be done with other than a 10 % randomint.
If you e.g. type .runrandom 10, which means it runs 10 times, you could possibly think of a "bug".
But to get a visible view of what Luth means, just try .runrandom 100000.
Nearly all values are around 10.000 this time, which is a good statistical outcome Surely they are not exact 10.000 cause its random  |
|
 |
|
|