Random Numbers and Lemonade Stand

4 posts / 0 new
Last post
Offline
Last seen: 2 weeks 6 days ago
Joined: Nov 21 2008 - 17:41
Posts: 52
Random Numbers and Lemonade Stand

I was looking over the program listing for Lemonade Stand, and the following line has me confused:

2230 IF RND ( - 1) < .5 THEN 2233

It seems to me that RND ( - 1 ) will always return 2.99196472E-08, and therefore it can never be < .5. Or am I not understanding how the RND command works?

Michael

amauget's picture
Offline
Last seen: 2 days 8 hours ago
Joined: Jan 3 2011 - 11:34
Posts: 341
Re: Random Numbers and Lemonade Stand

Michael,

It seems to be the correct beheviour. According to The AppleSoft II Basic Programming Reference Manual, it is stated on page 102 :

RND (aexpr)
If \aexpr\ is less than zero, RND(aexpr) generates the same random number each time it is used with the same \aexpr\, as if from a permanent random number table built into the APPLE.

Craig MX's picture
Offline
Last seen: 1 month 3 weeks ago
Joined: Aug 12 2004 - 22:43
Posts: 45
Re: Random Numbers and Lemonade Stand

I was looking over the program listing for Lemonade Stand, and the following line has me confused:

2230 IF RND ( - 1) < .5 THEN 2233

It seems to me that RND ( - 1 ) will always return 2.99196472E-08, and therefore it can never be < .5. Or am I not understanding how the RND command works?

Michael

It almost seems like someone was thinking in assembly while writing in BASIC. Forcing a 'conditional' jump to occur all the time during that statement's execution.

Then again it might just be a bug in the original programming, possibly intended to be RND(1)

Have you tried replacing the RND(-1) with RND(1) and evaluating the game-play? Who knows, maybe after all these years we'll see the secret cow-level with that change!

Smile

Cheers,
Craig

Offline
Last seen: 2 weeks 6 days ago
Joined: Nov 21 2008 - 17:41
Posts: 52
Re: Random Numbers and Lemonade Stand

Thanks for the replies. I haven't tried changing it yet, but I probably will test it out. I'll prolly trace the program flow on paper first because I doubt I'd notice the difference. I'm actually playing around with porting it for the C64 (the official Commodore version was pretty un-fun.) So far it works and graphics are similar but no music yet! It's a lot of fun and you can learn new ways of approaching problems from cross-platform conversion.

Michael

Log in or register to post comments