TIP: Click on subject to list as thread! ANSI
echo: cbm
to: ALL
from: SHAUN BEBBINGTON
date: 2018-04-18 23:34:00
subject: Re: C64 BASIC - what`s fa

After some experimenting it seems that I've been doing random numbers in CBM
BASIC completely wrong all of these years. Worse still, all of the examples in
the printed literature at the time had the wrong example as well. I assume this
is because firstly 
the least efficient way is more human readable, and secondly it would allow the
range of numbers to exceed a 16-bit signed integer range.

Here is the fastest way to make peusdo-random numbers happen inside the CBM
BASIC interpreter, assuming you want a positive integer of between zero and R:

X%=RND(.)*R

So, if you require a number higher than +32767, this is the fastest way:

X=INT(RND(.)*R)

The ordering seems to be important for optimisation as well, as R*RND(.) is
slower because the interpreter re-orders the calculation on the fly according
to its precedence.

I was never made aware of any of these facts as a child BASIC programmer.

Regards,

Shaun.

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.