C 随机数产生

// ConsoleApplication5.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <algorithm>
#include <vector>
#include <time.h>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    srand(unsigned(time(NULL)));//一定要这条,不然后面的结果每次运行都一样

    std::vector<char> vv;
    vv.push_back('1');
    vv.push_back('2');
    vv.push_back('3');
    vv.push_back('4');
    vv.push_back('5');
    vv.push_back('6');


    printf("before random_shuffle:\n");
    for(unsigned int i = 0; i < vv.size(); i++)
    {
        printf("vv is %c\n",vv.at(i));
    }

    random_shuffle(vv.begin(),vv.end()); //需包含头文件#include <algorithm>
    printf("after random_shuffle:\n");
    for(unsigned int i = 0; i < vv.size(); i++)
    {
        printf("vv is %c\n",vv.at(i));
    }

    return 0;
}

 

posted @ 2016-03-26 13:48  QQ76211822  阅读(137)  评论(0编辑  收藏  举报