So i have tried using rand(), and random but it results in the same problem each time, all strings created are duplicate. I think the problem may come from the number generator but i have no idea.
#include<iostream>
#include<unistd.h>
#include<fstream>
#include<string>
#include<cstdlib>
#include<time.h>
#include<random>
using namespace std;
int count;
char letter;
string word;
char ls[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'M', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis(0, 51);
string code()
{
for (int i = dis(gen) ; count != 13; count++){
word += ls[i];
i = dis(gen);
}
return word;
}
int main()
{
srand(time(0));
while(true){
cout << code() <<"\n";
srand(time(0));
}
sleep(10);
}
Aucun commentaire:
Enregistrer un commentaire