This question already has an answer here:
- Lack of randomness in C rand() 4 answers
I've been trying to figure out a way to generate a random integer number in C within a range of 0 to 1 (for true/false values). I'm not sure if there is a way to do that.
I've tried to manually program the random number function with for and while loops
int randomNumber;
for (randomNumber = 0; randomNumber<=1; randomNumber++) {
randomNumber = rand() % 100 + 1;
printf("%d\n", randomNumber);
}
I expect it to print out a random number (still analyzing this so not sure what it would print out), but I need the basis to getting the 0 and 1 for the true/false values.
Aucun commentaire:
Enregistrer un commentaire