View Single Post
  #108   Spotlight this post!  
Unread 20-12-2007, 04:17
Salik Syed Salik Syed is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Stanford CA.
Posts: 514
Salik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud of
Send a message via AIM to Salik Syed
Re: Programming jokes

Quote:
Originally Posted by artdutra04 View Post
The only downside to this algorithm is that there is no rand() function of any kind on our controller.

The best way I've found to generate "random" numbers on Vex/FRC controllers is to start a timer at the beginning of your program, and whenever you need a random number get the modulus of the timer value when divided by a number of your choice.
That is a pretty bad idea because you are bound to get high periodicity given this method if you need to generate random numbers sequentially.

a really simple way of doing it is to use a LCG (Linear Congruential Generator ... this is what the lcg_value function in php does)

X.0 is your seed

X.n+1 = (a*X.n + c) mod m

wikipedia suggests:
a = 1664525, c = 1013904223, m = 232

this is *still* not a great way to generate random numbers if you are doing simulations, but as far as FIRST applications go it should be pretty sufficient.
__________________
Team 701

Last edited by Salik Syed : 21-12-2007 at 03:32.