Is the random number generator seeded automatically?

thegwillthegwill Member Posts: 31
edited November -1 in Working with GS (Mac)
Does anyone know? (otherwise i'll need to do some testing...)

Comments

  • victorkin11victorkin11 Member Posts: 251
    I don't think so!
  • ORBZORBZ Member Posts: 1,304
    Yes, but with nothing useful. It is seeded with the MINUTE. More useful would be to seed it with radio noise AND let the devs set a seed value for deterministic randomization.

    The easiest thing to do to fix the problem is call this once at game start:

    Random(-abs(accelerometerX * 100), abs(accelerometerZ * 100))
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Just curious, what does that do exactly?
  • ORBZORBZ Member Posts: 1,304
    Calls the random function once with values that are outside the deterministic world of the computer.

    Acceleromter data is going to be subtle and different each time you hold the device. This "outside noise" is going to create a chain of random numbers.

    Of course this only works for devices, computers and web browsers return 0 for accelerometer data.

    Option B is to keep calling random inside a timer on the title screen. Since everyone presses start at slightly different moments the random function will have been called a non-deterministic number of times, thus seeding the chain.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Ok, Thanks!

    So, it took me a while to get it...

    random(1,100)

    If you only use random in a static way above, you will always get the same results throughout your app.

    Pulling from my limited Java knowledge, a random generator uses the last value as the seed for the next value, so forcing it to look at a "non-deterministic" variable preps the remaining static calls to the generator with a unique'ish starting seed. I think I got it now...
  • victorkin11victorkin11 Member Posts: 251
    I use the first click of the memu time to be a random seed
  • ORBZORBZ Member Posts: 1,304
    Victirkin,

    Isn't the first clock tick always 0.001?

    I'm not following you.
  • ORBZORBZ Member Posts: 1,304
    @bark

    Correct, except you only need to seed the chain with a non-deterministic value, or call random with static values a non-deterministic number of times before game start.

    Once this "seed" is done you can call random with static values.
  • thegwillthegwill Member Posts: 31
    thanks for all the responses guys (and gals?)
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    @ORBZ, I understand that. I think we're saying the same thing, I just said it poorly...lol ;-)
  • victorkin11victorkin11 Member Posts: 251
    ORBZ said:
    Victirkin,

    Isn't the first clock tick always 0.001?

    I'm not following you.

    I use game.time*100 when you click the menu!
  • PhoticsPhotics Member Posts: 4,172
    I'm surprised that GameSalad doesn't access the system clock. By using seconds, the random function could be more random. Plus, it could be used in the app to create some other dynamic effects... like how World of Warcraft is on a 24 hour schedule.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    I actually prefer it this way. It's just nice to know that it's repetitive unless you do something to randomize it.
Sign In or Register to comment.