home bbs files messages ]

Just a sample of the Echomail archive

Cooperative anarchy at its finest, still active today. Darkrealms is the Zone 1 Hub.

   CBM      Commodore Computer Conference      4,328 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,422 of 4,328   
   Herr Doktor to shaun@square-circle.co.uk   
   Re: C64 BASIC - what's faster INT() or %   
   27 Apr 18 15:55:56   
   
   What is the range of the random number you wish to generate?  Have you   
   considered just reading the value of the system timer?   
      
   On Mon, 16 Apr 2018 09:20:04 -0700 (PDT), Shaun Bebbington   
    wrote:   
      
   >There seems to be two ways to do integers on the C64 (and yes I know floats   
   are fastest), I was wondering about these two methods of generating a random   
   positive number between 1 and 64 inclusive:   
   >   
   >10 X=INT(64*RND(0)+1)   
   >   
   >or   
   >   
   >10 X%=64*RND(0)+1   
   >   
   >The latter saves two whole bytes, but is it faster to convert to integer   
   directly with the INT keyword, or is the implicit declaration below faster?   
   >   
   >Second question, let's say you want to generate a random number in multiple   
   places, you could use the above several times in a listing, but one could also   
   define a function as I understand it, like:   
   >   
   >0 DEF FN A(X)=X*RND(0)   
   >   
   >So each time in your listing, you will have,   
   >   
   >10 X%=FN A(39): Y%=FN A(24)   
   >...   
   >100 S%=FN A(10)+1: D%=FN A(10)+1   
   >   
   >etc...   
   >   
   >Other than less typing throughout the program (where you might have lots of   
   repeated random number generation in this example), are there any benefits to   
   using CBM functions? Does it save bytes overall would be perhaps one that I   
   could think of.   
   >   
   >Many thanks,   
   >   
   >Shaun.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: SpaceSST BBS Usenet  Fidonet Gateway (255:255/999)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca