I'm trying to generate a random number within range 1 to 20. So let's say I get 10. I would like the next random number to be close to the last random number so say 10.6 or 9.1. How would I give this this new random number a range that is close to the last one?
Current code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int min = 1, max = 20;
srand(time(0));
printf("The random number is: ");
int num = (rand() % (min - max));
printf("%d ", num);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire