Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!dsl.pitt.edu!pitt!willett!ForthNet From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: Mathematical routines Message-ID: <1722.UUL1.3#5129@willett.pgh.pa.us> Date: 13 Sep 90 03:02:06 GMT Organization: String, Scotch tape, and Paperclips. (in Pgh, PA) Lines: 49 Category 3, Topic 10 Message 55 Wed Sep 12, 1990 D.RUFFER [Dennis] at 00:29 EDT Re: CHARLIE HITSELBERGER > My question is, is the " 0 BEGIN DROP " a commonly used thing for > loops that leave a value on the stack upon exit? That is one way to do it Charlie. Here is another: : DICE ( -- n1 n2 ) 2 0 DO BEGIN RANDU 7 AND DUP 6 < NOT WHILE DROP REPEAT 1+ LOOP ; However, this method costs one more jump every time the loop repeats in place of the literal you had that was executed once. Of course, if your machine does a */ with any reasonable speed, you might also try the following: : DICE ( -- n1 n2 ) 2 0 DO RANDU 6 256 */ LOOP ; Depending on how fast your random algorithm is and how often, on average, it doesn't satisfy your test, this may actually be faster. In fact, if you are out for absolute speed, get rid of the DO...LOOP in the above example and you've done just about as much as you can. That is unless you want to re-code RANDU to do the 8 bit MOD for you. Then you would have: : DICE ( -- n1 n2 ) 6 RANDU 6 RANDU ; Well, you asked. DaR ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us