Jump to content
  • Advertisement
Sign in to follow this  
Zamv

How to seed the STL random_shuffle()?

This topic is 5457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm just using this algorithm on a vector but it is not seeded so of course generates the same sequence of random numbers every time the program is run. Any ideas? Many thanks, Zamv

Share this post


Link to post
Share on other sites
Advertisement
There is a version of random_shuffle that accepts a functor which it then uses as it's random number generator. If you write your own RNG functor (I don't know of one that comes standard with STL, but that doesn't mean there isn't), you could make it so you can seed your RNG before passing it to random_shuffle.

Share this post


Link to post
Share on other sites
I highly recommend using a better pseudo-random number generator than that piece of crap of STL's and you can just rearrange the vector by other means after having the new random indexes, or if mmelson is correct (I haven't used random_shuffle), just use one of the following functions as the random index generator with the random_shuffle. You can find the better ones from here for example: http://www.agner.org/random/. Mersenne twister is the fastest one of those which still has nice randomness but I prefer the combination of RANROT and Mother of All due to the fact that it's more random and still fast.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!