Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Someone complained about not enough Forth code

43 views
Skip to first unread message

Colin MacIntyre

unread,
May 18, 2011, 4:07:18 AM5/18/11
to
SPEC: Return a random number between 0 and 1, weighted to the latter 100% of the time.

needs random/gm

: randbyte rand temp tuck ! c@ ;
: 1or0 rand abs 0 do randbyte dup -1 > over 2 < and if unloop ;then drop loop 1or0 ;
: spec 1or0 drop 1 ;

Mark Wills

unread,
May 18, 2011, 4:45:30 AM5/18/11
to

: rand 1 ;

;-)

ron

unread,
May 18, 2011, 5:09:51 AM5/18/11
to

You may want to point out that you're writing Reva code, not ANS ...

Colin MacIntyre

unread,
May 18, 2011, 5:11:23 AM5/18/11
to
On Wednesday, May 18, 2011 4:45:30 PM UTC+8, Mark Wills wrote:

> On May 18, 9:07 am, Colin MacIntyre <mr.g...@gmail.com> wrote:
> > SPEC: Return a random number between 0 and 1, weighted to the latter 100% of the time.
> >
> > needs random/gm
> >
> > : randbyte  rand temp tuck ! c@ ;
> > : 1or0      rand abs 0 do randbyte dup -1 > over 2 < and if unloop ;then drop loop 1or0 ;
> > : spec      1or0 drop 1 ;
>
> "weighted to the latter 100% of the time"
>
> : rand 1 ;
>
> ;-)

Nice try, but that is definitely not enough Forth code. :)

Colin MacIntyre

unread,
May 18, 2011, 5:17:08 AM5/18/11
to
On Wednesday, May 18, 2011 5:09:51 PM UTC+8, ron wrote:

> On May 18, 11:07 am, Colin MacIntyre <mr.g...@gmail.com> wrote:
> > SPEC: Return a random number between 0 and 1, weighted to the latter 100% of the time.
> >
> > needs random/gm
> >
> > : randbyte  rand temp tuck ! c@ ;
> > : 1or0      rand abs 0 do randbyte dup -1 > over 2 < and if unloop ;then drop loop 1or0 ;
> > : spec      1or0 drop 1 ;
>
> You may want to point out that you're writing Reva code, not ANS ...

That is true!

BruceMcF

unread,
May 18, 2011, 9:32:49 AM5/18/11
to

Ah, here's the same with "more Forth code":

1 CONSTANT rand-init
VALUE {rand}

: seed-rand rand-init TO {rand} ;
seed-rand

: rand {rand} ;

What was the purpose of "more Forth code" to output a constant, again?
I'm not sure I caught that part.

Colin MacIntyre

unread,
May 19, 2011, 2:29:29 AM5/19/11
to
Nice work! Once we have enough Forth code, surely something good will happen.

ron

unread,
May 19, 2011, 3:18:20 AM5/19/11
to
On May 19, 9:29 am, Colin MacIntyre <mr.gao...@gmail.com> wrote:
> Nice work! Once we have enough Forth code, surely something good will happen.

We might even get that AI singularity going!

DROP TUCK ROLL BYE

Colin MacIntyre

unread,
May 19, 2011, 4:15:39 AM5/19/11
to
On Thursday, May 19, 2011 3:18:20 PM UTC+8, ron wrote:

> On May 19, 9:29 am, Colin MacIntyre <mr.g...@gmail.com> wrote:
> > Nice work! Once we have enough Forth code, surely something good will happen.
>
> We might even get that AI singularity going!

lol

>
> DROP TUCK ROLL BYE

Hugh Aguilar

unread,
May 19, 2011, 8:20:56 PM5/19/11
to

Maybe he means that the random numbers are supposed to be triangularly
distributed. That is what my BIAS does (except leaning toward 0 rather
than toward the upper limit). All of this is in my novice package
(PRNG returns a pseudo-random cell value).

macro: rnd ( ulimit -- uvalue )
prng um* nip ;

macro: bias ( ulimit -- uvalue )
dup rnd over rnd um*
rot um/mod nip ;

0 new messages