c++ 随机数 产生不重复的随机数

    

#include <algorithm>
srand( (unsigned)time(NULL) ); //设置随即数生成器的种子  
    vector<unsigned int> vecRand; 

    if (m_pPlayerArray != NULL)
    {
        unsigned  int unObjCount = m_pPlayerArray->count();
        for (unsigned int num = 0; num < unObjCount; ++num)  
        {  
            vecRand.push_back(num);  
        }  
    }
//乱序
    random_shuffle(vecRand.begin(), vecRand.end());

 

posted @ 2013-06-03 10:26  呆呆笨笨  阅读(2507)  评论(0编辑  收藏  举报