Author Topic: Seeding the Random Number Generator  (Read 6481 times)

0 Members and 1 Guest are viewing this topic.

Offline PickleMan

  • LV0 Newcomer (Next: 5)
  • Posts: 3
  • Rating: +0/-0
    • View Profile
Seeding the Random Number Generator
« 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.

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: Seeding the Random Number Generator
« Reply #1 on: March 10, 2012, 11:31:28 am »
I don't think you can seed it...
(i might be wrong tho)
« Last Edit: March 10, 2012, 11:32:53 am by epic7 »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Seeding the Random Number Generator
« Reply #2 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) ???)
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Seeding the Random Number Generator
« Reply #3 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 :)
(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.
« Last Edit: March 10, 2012, 11:37:06 am by Deep Thought »




Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Seeding the Random Number Generator
« Reply #4 on: March 10, 2012, 11:37:43 am »
Seed signifie la valeur qui va initier le générateur. Ca signifie aussi "graine"...
Here
Ninja'd
« Last Edit: March 10, 2012, 11:38:09 am by Eiyeron »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Seeding the Random Number Generator
« Reply #5 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
Ninja'd
(Ok, thanks :). And I knew it had something to do with plants :P)
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline PickleMan

  • LV0 Newcomer (Next: 5)
  • Posts: 3
  • Rating: +0/-0
    • View Profile
Re: Seeding the Random Number Generator
« Reply #6 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.

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Seeding the Random Number Generator
« Reply #7 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?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Seeding the Random Number Generator
« Reply #8 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 :)




Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Seeding the Random Number Generator
« Reply #9 on: March 10, 2012, 11:52:42 am »
You could also write a sub routine to generate pseudo-random numbers that can be seeded >.>

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Seeding the Random Number Generator
« Reply #10 on: March 10, 2012, 01:04:17 pm »
that^
Welcome.
I'm not a nerd but I pretend:

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Seeding the Random Number Generator
« Reply #11 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
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Seeding the Random Number Generator
« Reply #12 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
« Last Edit: March 10, 2012, 03:37:48 pm by Runer112 »