[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: |
Tue, 08 Aug 2017 21:27:31 +0200 |
User-agent: |
Roundcube Webmail/1.2.4 |
James Gere <address@hidden> writes Re: how to build a really working
random seed ?
Dear Marcel,
did you try 5 or 6?
James Gere
No, I did not, thanks!
The generator is even more puzzling than I thought
(unless I made an conversion mistake from 32 -> 64 bits)
-- see the test below.
To short circuit the test, enter
1073741825 xtest .
Apparently this generator has a cycle of 0 for the initial seed
1073741825.
The test finds other initial values that result in very short cycles.
There might be an initial value that results in a maximum length
sequence > 1685616737, but this sequence may have 'holes.'
-marcel
-----------------------------------------------------
variable (rnd)
0 VALUE minimum
: rnd ( -- n )
(rnd) 32B@
dup #13 lshift xor $FFFFFFFF and
dup #17 rshift xor $FFFFFFFF and
dup DUP 5 lshift xor (rnd) 32B! ;
: (xtest) ( maxcycle x -- cycle )
DUP (rnd) !
SWAP 0 ?DO rnd over = IF CR ." start = " .
#20 HTAB ." -- short cycle of " I DEC.
I UNLOOP EXIT
ENDIF
LOOP
DROP $7FFFFFFF ;
: xtest ( start -- )
$7FFFFFFF TO minimum
CR ." Searching for the shortest cycle."
( start )
BEGIN
minimum OVER (xtest)
( -- start u ) minimum MIN TO minimum
( start ) 1+
minimum 0=
UNTIL ( start ) DROP ;
DOC
(*
Searching for the shortest cycle.
start = 1 -- short cycle of 1685616737
start = 2 -- short cycle of 1198653427
start = 3 -- short cycle of 950033464
start = 4 -- short cycle of 683909353
start = 7 -- short cycle of 446874342
start = 29 -- short cycle of 395322450
start = 49 -- short cycle of 233610872
start = 68 -- short cycle of 160881270
start = 169 -- short cycle of 58748379
start = 266 -- short cycle of 7897721
start = 276 -- short cycle of 5522514
start = 1040 -- short cycle of 1268127
start = 2403 -- short cycle of 465414
start = 10032 -- short cycle of 228244
start = 70110 -- short cycle of 176576
start = 71298 -- short cycle of 84339
start = 123235 -- short cycle of 14938
start = 672951 -- short cycle of 2835
start = 1048315 -- short cycle of 1558
start = 3457816 -- short cycle of 189
start = 9516354 -- short cycle of 143
start = 22220153 -- short cycle of 116
start = 145584897 -- short cycle of 106
start = 310366040 -- short cycle of 64
start = 552122674 -- short cycle of 30
start = 729376685 -- short cycle of 3
start = 1073741825 -- short cycle of 0
*)
ENDDOC
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [gforth] how to build a really working random seed ?,
mhx <=