Quote:
Originally Posted by artdutra04
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.