I'd like to get a better feeling for how random the result from RANDOM is. Any comments?
I'd like to get a better feeling for how random the result from RANDOM is. Any comments?
Russ
N0EVC, xWB6ONT, xWN6ONT
"Easy to use" is easy to say.
IF you use the same seed value every time, yes, it repeats the same sequence every 65535 time.
However, whenever I'm using RANDOM, I use a whatever 16-bit I have free as the seed value. That works as long as I'm not grabbing the 16-bit timer value at the same exact time every time.
http://www.picbasic.co.uk/forum/showthread.php?t=7555&
If you want something really random... white noise generator fed to an internal PIC counter + using a random sampling time... even the white noise generator with Count would probably do.
Tons of way to Fry and egg
Tons of way to Skin a Cat
Every road leads to Roma
Choose the one who fits your local expression![]()
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
I guess my question was a little broad. Let me refine it.
For example, were I to generate random intervals between 1 and 10 seconds long (inclusive) doing this:
. . . can I expect the distributions to "look" really random? (In 100 loops, can I expect to see about 10 of each value in each category of 1 second, 2 seconds . . . 10 seconds, etc.?) And, in the sequence, will I see a discernable pattern?Code:SEED=32771 LOOP: RANDOM SEED TIME=(SEED//10)+1 TIME=1000*TIME HIGH LED PAUSE TIME LOW LED PAUSE 1000 GOTO LOOP END
In some small BASIC implementations, I've had to do the equivalent of this:
. . . in order to get good distributions of small numbers.Code:SEED=32771 LOOP: RANDOM SEED TIME=(SEED//11)+1 IF TIME<2 OR TIME>10 THEN GOTO LOOP TIME=1000*TIME HIGH LED PAUSE TIME LOW LED PAUSE 1000 GOTO LOOP END
Russ
N0EVC, xWB6ONT, xWN6ONT
"Easy to use" is easy to say.
Probably you'll have better results if you change the SEED value.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks