0
\$\begingroup\$

And here is the random number generator again.

I work on a game, where a user can create and schedule some levels to player later. For simplicity, let's say I play chess.

I create a new game with AI or an opponent for specific datetime in the future.

The random number generator gets as seed the current timestamp when the user create the game and put the pawn in random positions.

If the user creates too many games at once, the results on pawns positions are identical.

So, I was wondering, what other strategies are out there on picking the right seed number instead of the timestamp.

\$\endgroup\$
  • 1
    \$\begingroup\$ can we see some code? platform? Language? Engine? We can´t really help much with this information \$\endgroup\$ – Mayuso Jan 15 '16 at 12:06
1
\$\begingroup\$

Some aspects of your issue are a little unclear, but it appears you're using a windows very not-so-precise time, and calling it many times in a row.

There are a couple of ways to work around this:

  • Use a more precise timer: Make sure that the timestamp value you get is really the most precise that your system can offer.
  • Take the timestamp at the start of your game, and create a unique counter of times the generation has been called. Add the value of the counter to the timestamp and use that as the seed for each generation. This will ensure that the seed will be different for each generation.
\$\endgroup\$
  • \$\begingroup\$ This the second one could work. Since there is already implemented something like the counter you mention. Thanks \$\endgroup\$ – Tasos Jan 15 '16 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.