Witam serdecznie
do generowania losowego ciągu liter i liczb używam kodu:
#include <iostream>
#include <random>
#include <algorithm>
#include <chrono>
std::string chars {"abcdefghijklmnopqrstuvwxyz1234567890"};
std::random_device rd;
std::mt19937 generator(rd());
std::string rand_str(int length) {
std::string output;
output.reserve(length);
while(length>0)
{
auto randNumb = generator();
while(randNumb > 33 && length--)
{
output.push_back(chars[randNumb%33]);
randNumb/=33;
}
}
return output;
}
int main() {
std::string rand_bytes;
rand_bytes = std::move(rand_str(64));
std::cout << "This took: " <<rand_bytes<< std::endl;
}
Tylko jest jeden zasadniczy problem.. Jak uruchomię powyższy program to uzyskam tą samą kombinację znaków..
r7ijv3tr1gxnmhjnhfaqwapbr1ggz45nh7uj4ix4i4nosxbnekigtc1uaidcveu2
Co zrobić? Może ktoś zna lepszy kod? Co zrobić aby każda funkcja zwracała inną wartość..