| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: C64 BASIC - what`s faster INT() or %? Plus benefits of DEF FN A() |
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) SEEN-BY: 57/0 116/102 153/150 250 317/2 3 393/68 633/267 280 640/384 712/620 SEEN-BY: 712/848 770/0 1 3 100 340 772/0 1 210 500 @PATH: 770/3 1 712/848 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
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™.