Re: Random Distribution in Forth



mhx@xxxxxx (Marcel Hendrix) wrote in news:01003428173560@xxxxxxxxxxxxxx:

jrh <no@xxxxxxxx> writes Re: Random Distribution in Forth
<clip>

1 EQU MASK
: RAND1+/- ( n -- n+1/-1 ) RAND MASK AND IF 1- ELSE 1+ THEN ;

Guessing that 'EQU' is CONSTANT

A literal constant.

MASK could be any power of two depending on which bit is being tested.

and RAND a random number generator,

Yes, RANDOM might be the word in ANSI Forth.

I assume:

: RAND1+/- ( n -- n+1/-1 )
RAND MASK AND \ get a single random bit
IF 1- \ bit = '1' : increment n
ELSE 1+ \ bit = '0' : decrement n
THEN ;

You have chosen to convert the lowest bit of the random number
generator to '1' / '-1'. Most PRNG have bad lower bits. Is MASK
set to 1 on purpose?

The actual program tests all 64 bits, the counters for
some bits never get back to zero, even after millions of cycles.

: TEST-RAND { n - t - t }
0 -> t

This is unfamiliar locals syntax (for me).
You mean 0 { n t -- u } ?
Our locals were implimented before the standard and work a little
different, n is defined from the stack , t is undefined and must
be initialized.

0 n 0
?DO RAND1+/- DUP 0=
IF t 1+ -> t THEN
LOOP t
;

So you randomly add +1 or -1 to 0, and do
this n times. The number of times the running sum becomes
0 is counted (in t).

Yes, and if RAND was producing and equal number of ones and zeros
you would think the counter should keep crossing zero, not
drift off in a positive or negative direction.

\ If RAND is linear
\ What is the function of n for the average value of t

Linear? You mean uniform?

Yes, all numbers have the same chance of being generated.

All for now,
jrh


.



Relevant Pages

  • Re: [PATCH] x86: set PAE PHYSICAL_MASK_SHIFT to match 64-bit
    ... we can fix it later in a separate patch. ... I'm trying to think how many places have compile-time constants derived from this mask. ... we won't use them since we know the size of the address space and thus will leave them at zero. ... Certainly virtual is fixed at 48 bits, but I don't think there's any deep reason why physical needs to be within 3 bits. ...
    (Linux-Kernel)
  • Re: [PATCH] x86: set PAE PHYSICAL_MASK_SHIFT to match 64-bit
    ... I'm trying to think how many places have compile-time constants derived from this mask. ... we won't use them since we know the size of the address space and thus will leave them at zero. ... Certainly virtual is fixed at 48 bits, but I don't think there's any deep reason why physical needs to be within 3 bits. ...
    (Linux-Kernel)
  • Re: Determining what should be blocked in and out?
    ... mask, the .0, will always make the last byte of the IP address you're ... zero always for the purposes of checking if it's to be blocked. ... IP address you are trying to contact is on the same network as you. ... Since this equals the same network to be blocked, ...
    (comp.security.firewalls)
  • Re: [PATCH] mask ADT: bitmap and bitop tweaks [1/22]
    ... And 2.6.4 deviates from my bitmap model by a couple of *_complement ... the CPU_MASK_ALL code for large systems ... If input tails are zero, then output tails will be zero. ...
    (Linux-Kernel)
  • Re: Heisenbug in Intels MINLOC()
    ... "If ARRAY has size zero or every element of MASK has the value false, all elements of the result are zero." ... pretty egregious error when it states the result is processor dependent. ...
    (comp.lang.fortran)