I am currently using the time() function inside srand() to generate a completely different and random number everytime the program is run.
srand(time(NULL));// chooses random seed for a different rand() every run
int n = 1 + rand() / (RAND_MAX / (100 - 1 + 1) + 1); // only generates numbers between 1 and 100
printf("n = %d",n);
int a = rand();
printf("\na = %d",a);
int b = rand();
printf("\nb = %d",b);
Unfortunately, I have learned that I am not allowed to use time() or getpid(). Is there a way, using ONLY <stdio.h>, <stdlib.h> <assert.h> to generate a different random number every time the program is run?
Aucun commentaire:
Enregistrer un commentaire