lundi 10 avril 2017

How to print random values between certain range?

I am writing a basic crypto program using c language. In that i want to get a random numbers form certain range say (97 to 122). I saw this program on some programming website.

int main(void) 
{
  int c, n;

  printf("Ten random numbers in [1,100]\n");

  for (c = 1; c <= 10; c++) 
  {
    n = rand() % 100;
    printf("%d\n", n);
  }

}

but it prints random values from 1 to 100. In python we implement it with the help of rand() function eg: r = random.randint(97, 122). so is there any way to implement like this in c program.




Aucun commentaire:

Enregistrer un commentaire