Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: PickleMan on March 10, 2012, 11:29:07 am
-
How can I seed the random number generator. I already tried X->rand and it just threw a syntax error.
-
I don't think you can seed it...
(i might be wrong tho)
-
(Sorry for the stupid question but I am French and I don't understand the word "seed" in this context (I thought it was for plants) ???)
-
There's no way to seed the random number generator in Axe—the commands listed in the Commands.html are exactly everything you can do in Axe, no more.
However, Axe uses a single byte in your program to keep the running seed (the R register is used to manipulate it). Theoretically it's possible to find the location of that seed and store your own value to it, but it would involve quite some work because it's part of Axe's rand routine and so could be anywhere in your program. You could write a snippet in Z80 assembly to look for it, but it's almost definitely not worth the effort.
And welcome to Omnimaga, Pickleman! If you have time, you can introduce yourself here (http://www.omnimaga.org/index.php?board=10.0) :)(Sorry for the stupid question but I am French and I don't understand the word "seed" in this context (I thought it was for plants) ???)
It means to set an initial value or a place to start to a random number generator. In TI-BASIC you'd use int→rand.
-
Seed signifie la valeur qui va initier le générateur. Ca signifie aussi "graine"...
Here (http://fr.wikipedia.org/wiki/Graine_al%C3%A9atoire)
Ninja'd
-
(Sorry for the stupid question but I am French and I don't understand the word "seed" in this context (I thought it was for plants) ???)
It means to set an initial value or a place to start to a random number generator. In TI-BASIC you'd use int→rand.
Seed signifie la valeur qui va initier le générateur. Ca signifie aussi "graine"...
Here (http://fr.wikipedia.org/wiki/Graine_al%C3%A9atoire)
Ninja'd
(Ok, thanks :). And I knew it had something to do with plants :P)
-
Hm, so there's no way at all to make sure two calculators connected via link cable have the same seed...perhaps I just have one calculator calculate the random numbers and send them over when needed.
-
I think you're wrong: you can always send the value which will be your seed, nah?
-
Hm, so there's no way at all to make sure two calculators connected via link cable have the same seed...perhaps I just have one calculator calculate the random numbers and send them over when needed.
Oh, if you're trying to do that, then it gets much harder—Axe also uses R for its random number generator, so unless you can make sure that each calculator does exactly the same thing at all times (which would be pretty impossible if one's sending and one's receiving), you can't keep the random numbers in step.
Generating them on one side and sending them over sounds like a good plan :)
-
You could also write a sub routine to generate pseudo-random numbers that can be seeded >.>
-
that^
Welcome.
-
Btw, you can seed the RNG with 0->{orand}r. But it doesn't mean anything because it also uses the R register (which is like a mini clock) AND it makes random reads from memory. So you would literally have to have identical calculators, the same programs, both running exactly the same time, which is impossible if you do linking.
The problem is that rand provides and actual random number, you want a seed-able pseudo-random number. Here is a good algorithm for generating such a number:
S*7+4*3-1->S
-
Optimized. ;)
S*7*3+11→S
EDIT: Alternatively, to save 4 bytes (as long as you already use general multiplication elsewhere) at the cost of, on average, 666 cycles:
S*21+11→S