random_shuffle not really random

前端 未结 3 1210
栀梦
栀梦 2020-12-20 15:31

I\'m using the random_shuffle on a vector like this:

#include 
vector  deck;
//some code to add cards to the deck h         


        
3条回答
  •  醉话见心
    2020-12-20 16:20

    Place the line:

    srand (time (0));
    

    in your code before you do anything else, such as at the start of main().

    Without that, the default seed of 1 will always be used, leading to identical sequences from rand() and anything that uses it.

提交回复
热议问题