Category : random

SOLVED Thank you to @RetiredNinja for pointing out that the problem wasn’t with srand() but rather with the improper calling of functions in my array. Using a switch statement to call the functions properly fixed the issue. while (numberOfCharacters > 0){ int random = rand()%4; switch(random){ case 0: password += randomLowerCharacter(); break; case 1: password ..

Read more

Is it reasonable to expect that a distribution from <random> re-initialized before each next number request behaves the same way as if it was initialized once? In other words, does this: std::default_random_engine generator; int p[10]={}; for (int i=0; i<nrolls; ++i) { std::uniform_int_distribution<int> distribution(0,9); int number = distribution(generator); ++p[number]; } have the same distribution as that ..

Read more

Basically my program randomly generates 32 alpha numeric strings and I want to add hyphens between the characters exactly like this format 56C13783-RR1B-1B66-7685-83C9343667AE. My code before trying to add changes was previously in this format EA25D82041974B9089459223D74E84DA. #include <iostream> #include <string> #include <cstdlib> /* srand, rand */ #include <ctime> using namespace std; string RandomString(int len) { ..

Read more