I'm trying to automate test cases for my program and i wanted to generate random strings of numbers to test with... First test will be with base 2 numbers, so i want to generate 0's and 1's, of a random length n, where n is from 1 to 100. This is what i have so far, and it keeps returning the same string, (same length) and only generates either a 1, or a 0 for the entire length of the string.
int digNum = rand() % 100 + 1;
int num;
for(int i = 0; i < digNum; i++) {
num = ((double) rand() / (RAND_MAX)) + 1;
s1 = s1 + to_string(num);
}
cout << s1 << endl;
Thoughts?
Aucun commentaire:
Enregistrer un commentaire