那不就是我说的意思吗?
---------
在开玩笑吗? 那不就是 1 到1000吗?...
你不如说" 把1 到1000的排列打乱"...
女侠,约吗?
try the following code to see if it works for you.
HJin
===========================================================
/*---------------------------------------------------------------------------
File name: random_shuffle_fuctor.cpp
Author: HJin (email: fish_sea_bird [at] yahoo [dot] com )
Created on: 8/11/2007 15:57:48
Environment: Windows XP Professional SP2 English +
Visual Studio 2005 v8.0.50727.762
Modification history:
===========================================================================
Note that the internal "rand()" function is not a good one, you may
want to use a better one.
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
using namespace std;
class RandFunctor
{
public:
RandFunctor()
{
srand(time(0));
}
int operator()(int m)
{
return (rand()| (rand()<<16) )%m;
}
};
int main()
{
const int kSize=20;
int i;
vector<int> vi(kSize);
for(i=0; i<kSize; ++i)
vi[i] = i+1;
RandFunctor rf;
std::random_shuffle(vi.begin(), vi.end(), rf);
std::copy(vi.begin(), vi.end(), ostream_iterator<int>(cout, " "));
cout<<endl;
return 0;
}