Jeg bruger C++
Et simpelt eksempel fra rodekassen:
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
class RandomClass
{
public:
RandomClass()
{
srand(time(0));
}
int operator()(int aRange)
{
return int(1.0*aRange*rand()/RAND_MAX);
}
};
int main()
{
std::vector<int> Vector;
int a;
for(a = 0; a < 52; a++)
Vector.push_back(a);
RandomClass Rand;
std::random_shuffle(Vector.begin(), Vector.end(), Rand);
for(a = 0; a < 52; a++)
std::cout << Vector[a] << std::endl;
int Array[52];
for(a = 0; a < 52; a++)
Array[a] = a;
std::random_shuffle(Array, &Array[52], Rand);
for(a = 0; a < 52; a++)
std::cout << Array[a] << std::endl;
return 0;
}
Er der nogen grund til at du ikke benytter C/C++ foraet?