dimanche 25 août 2019

How do you generate a random boolean in C? [duplicate]

This question already has an answer here:

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