home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.sys.cbm      Discussion about Commodore micros      53,866 messages   

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

   Message 52,234 of 53,866   
   Shaun Bebbington to All   
   Re: C64 BASIC - what's faster INT() or %   
   18 Apr 18 23:34:56   
   
   From: shaun@square-circle.co.uk   
      
   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: you cannot sedate... all the things you hate (1:229/2)   

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


(c) 1994,  bbs@darkrealms.ca