gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gforth] how to build a really working random seed ?


From: mhx
Subject: Re: [gforth] how to build a really working random seed ?
Date: Mon, 17 Jul 2017 21:56:28 +0200
User-agent: Roundcube Webmail/1.2.4

Andrew Haley wrote:
...

My negative comment was wrong, indeed. There is no
stack error and the length of the cycle is 2^32 - 1:
"n xtest ." returns n, at least for all
n I tried.

variable (rnd)

: rnd ( -- n )
        (rnd) 32B@
        dup #13   lshift xor $FFFFFFFF and
        dup #17   rshift xor $FFFFFFFF and
        dup DUP 5 lshift xor (rnd) 32B! ;

: xtest ( x -- )
        1 (rnd) !
        $100000000 0 DO  rnd over = ?LEAVE  LOOP
        ." outcome = " H. ;

-marcel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]