Project

General

Profile

Random Number Generator (edit)

Added by Rolf about 1 year ago

At the first glance I did not find it in Mecrisp forth, so I wrote my own. May be it is useful for others. It generates a Maximum Length Sequence of (2**32)-1 32-bit-numbers (according to theory the frequency spectrum should be constant (white noise)). It fetches its root value from a variable (BUF32) and leaves the result there. Example: m32 BUF32 @ . prints the next value. To change the sequence, put another root value in BUF32.

Oops! Just found that there is already one in the embello repository: random.fs - Sorry, but its not that easy to keep an overview with this huge amount of information at jeelabs.

m32.fs (265 Bytes) m32.fs Maximum Length Sequence Generator

Replies (1)

RE: Random Number Generator (edit) - Added by jcw about 1 year ago

Nice demo, I'll take the liberty to add your code inline here, since it's only a few lines:

8374659 variable BUF32

: m32 ( -- )

BUF32 @ 1 lshift
dup $00002000 and if
  dup $40000000 and if
    $fffffffe and BUF32 !
  else
    $00000001 or BUF32 !
  then
else
  dup $40000000 and if
    $00000001 or BUF32 !
  else
    $fffffffe and BUF32 !
  then
then

;

As for your second comment:

it's not that easy to keep an overview with this huge amount of information at jeelabs

Agreed. I welcome suggestions for improvement and help to add up-to-date information to the "official" documentation site at https://docs.jeelabs.org.
There's also the somewhat older http://embello.jeelabs.org area, which illustrates part of the problem: too much info in too many different places!
One task ahead is to merge it all back into the docs site, which can be edited by anyone with commit access, or forked + PR'd by everyone else.

    (1-1/1)