Author Topic: help me understand random seed.  (Read 2874 times)

0 Members and 1 Guest are viewing this topic.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
help me understand random seed.
« on: June 20, 2011, 11:13:52 am »
so how does seed work?
what does it do?
EX:
3->rand

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: help me understand random seed.
« Reply #1 on: June 20, 2011, 11:20:24 am »
It's very important to realize that it's extremely hard to ever create a 'random' number in computers.  Computers don't do random. 

Instead, the next best alternative is creating 'pseudo-random' numbers -- numbers, that on the surface, seem random, but are actually determined by a complex formula.

The seed is the initial value that you are feeding the 'rand' function.  The calculator (and all random-number-generators) takes the seed, and feeds it into a complex function that will output a pseudo-random number.  It then takes that pseudo-random number and feeds it back into the rand function the next time it is called.

You can exploit this effect: if you constantly store the same seed, the output value will be identical each time.


tl;dr:
You can't do random numbers on computers, instead, you feed a function a seed number, and it transforms that seed into something that's random enough.


(And if I got anything wrong, or am unclear, feel free to point it out :))
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: help me understand random seed.
« Reply #2 on: June 20, 2011, 11:34:51 am »
oh i see... :P i read alot about this in internet, but couldnt really understand. Anyways, thanks for explanation!:D

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: help me understand random seed.
« Reply #3 on: June 20, 2011, 11:38:13 am »
No problem!
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: help me understand random seed.
« Reply #4 on: June 20, 2011, 01:17:39 pm »
This is also useful if you are trying to test some encryption program, or a game that uses random values, and you want them to be the same each test in case you are testing a specific bug and you don't know if it's related to the random number generator (RNG) or your code.