Re: Random Distribution in Forth
- From: jrh <no@xxxxxxxx>
- Date: Fri, 29 Jun 2007 08:13:21 GMT
mhx@xxxxxx (Marcel Hendrix) wrote in news:01003428173560@xxxxxxxxxxxxxx:
jrh <no@xxxxxxxx> writes Re: Random Distribution in Forth
<clip>
1 CONSTANT MASK
: RAND1+/- ( n -- n+1/-1 ) RANDOM MASK AND IF 1- ELSE 1+ ENDIF ;
: TEST-RAND ( n -- u )
0 LOCALS| t n |
0 n 0
?DO RAND1+/- DUP 0=
IF 1 +TO t ENDIF
LOOP
DROP t ;
<clip>
Extra tool:
: tt ( tries -- )
0 0 LOCALS| ix maxi nmax |
BEGIN
1 +TO ix
nmax TEST-RAND
DUP maxi > IF CR ix . 2 SPACES DUP . TO maxi
ELSE DROP
ENDIF
KEY?
UNTIL
CR ix . ." tries for nmax = " nmax . ;
( Take care, this may unveil a hitherto unknown quirk in the
iForth random generator )
So, I guess you are asking what distribution the random output
follows? And also, how does the value of nmax influence the
'randomness' of the result?
Presumably some of our mathematically/physics inclined contributors
will know. I would have to consult the books at this point, but
my intuition says it is probably a well-known distribution.
-marcel
The random generator under test (RANROT64) had a much different output
1 5
2 7
32 9
95 11
281 13
4076 14
15816 15
(esc)
342635 tries for nmax =30
Do you have the code for the iFORTH random generator?
jrh
.
- References:
- Random Distribution in Forth
- From: jrh
- Re: Random Distribution in Forth
- From: Marcel Hendrix
- Random Distribution in Forth
- Prev by Date: Re: Build your own Forth for Microchip PIC: Design thoughts
- Next by Date: Re: Gforth and gcc "progress"
- Previous by thread: Re: Random Distribution in Forth
- Next by thread: yapcp -- 64 bit
- Index(es):