Re: Marcel's Random-Function

James Gere <[email protected]>
Newsgroups gmane.comp.lang.forth.gforth
Message-ID <CAB21L-2r1JU5ZxaT-AsViSuDfAkH-S1QgRRC=1MXPEu0YoU-PQ@mail.gmail.com>
  Hi, Marcel,
                      as a first installment on earlier promises, here are
the inverse functions as GForth code:


include random.fs \ need 'rnd' for test

variable (rnd)    \ for marcel's rnd

\ note:  for "dup shift xor," all the inverse functions
\ start with  the original functions

:  turn-around ( n -- n' )   dup 5 lshift xor ;
: -turn-around ( n -- n' )   turn-around
    dup 10 lshift xor  dup 20 lshift xor ;

:  take-off2nd ( n -- n' )   dup 17 rshift xor ;
: -take-off2nd ( n -- n' )   take-off2nd ;

:  take-off1st ( n -- n' )   dup 13 lshift xor ;
: -take-off1st ( n -- n' )   take-off1st       dup 26 lshift xor ;

\ note: here we reverse order for inverses because
\ the lshifts and rshift don't commute
:  take-off    ( n -- n' )    take-off1st  take-off2nd ;
: -take-off    ( n -- n' )   -take-off2nd -take-off1st ;

:  marcel ( -- n )   (rnd) @  take-off    dup  turn-around  (rnd) ! ;
: -marcel ( -- n )   (rnd) @ -turn-around dup -take-off     (rnd) ! ;

: tst   begin  cr rnd ( <-<< time based random number ) dup .
         (rnd) !  marcel dup .  -take-off . -marcel .
\ the check is 1st# = 3rd#  and  2nd# = 4th#
          key 10 = until ;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.