Answer the question
In order to leave comments, you need to log in
rand() works strangely. What is the problem?
Hey! I have a function:
char generate_asterisk_or_space() {
srand(static_cast<int>(time(0)));
int num = rand() % 2;
switch (num) {
case 0:
return '_';
case 1:
return '*';
default:
return '_';
}
}
Answer the question
In order to leave comments, you need to log in
Set the seed once - before forming the array. With a release build, the value returned by time is most likely the same. Example:
srand(static_cast<int>(time(0)));
for( int i =0; i<array_length; i++){
rand_array[i] = generate_asterisk_or_space();
}
With it, I form an array,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question