Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: PickleMan on March 10, 2012, 11:29:07 am

Title: Seeding the Random Number Generator
Post 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.
Title: Re: Seeding the Random Number Generator
Post by: epic7 on March 10, 2012, 11:31:28 am
I don't think you can seed it...
(i might be wrong tho)
Title: Re: Seeding the Random Number Generator
Post by: Hayleia on March 10, 2012, 11:35:06 am
(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) ???)
Title: Re: Seeding the Random Number Generator
Post by: Deep Toaster on March 10, 2012, 11:36:41 am
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.
Title: Re: Seeding the Random Number Generator
Post by: Eiyeron on March 10, 2012, 11:37:43 am
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
Title: Re: Seeding the Random Number Generator
Post by: Hayleia on March 10, 2012, 11:39:34 am
(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)
Title: Re: Seeding the Random Number Generator
Post by: PickleMan on March 10, 2012, 11:42:15 am
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.
Title: Re: Seeding the Random Number Generator
Post by: Eiyeron on March 10, 2012, 11:43:50 am
I think you're wrong: you can always send the value which will be your seed, nah?
Title: Re: Seeding the Random Number Generator
Post by: Deep Toaster on March 10, 2012, 11:44:42 am
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 :)
Title: Re: Seeding the Random Number Generator
Post by: Xeda112358 on March 10, 2012, 11:52:42 am
You could also write a sub routine to generate pseudo-random numbers that can be seeded >.>
Title: Re: Seeding the Random Number Generator
Post by: aeTIos on March 10, 2012, 01:04:17 pm
that^
Welcome.
Title: Re: Seeding the Random Number Generator
Post by: Quigibo on March 10, 2012, 03:16:08 pm
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:

Code: [Select]
S*7+4*3-1->S
Title: Re: Seeding the Random Number Generator
Post by: Runer112 on March 10, 2012, 03:22:19 pm
Optimized. ;)

Code: [Select]
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:

Code: [Select]
S*21+11→S