jeudi 2 janvier 2020

so how can i generate random numbers with rand()?

Hello guys i need help with this little code i have made. The problem is that i want it to generate randome numbers from 1000 to 9999. But if you run it, it gives and numbers above from 9999...i have read some forums about the correct way to use rand() but nothing.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{

    int w = 0;
    int mi;
    int i;
    srand(time(0));
    for(i=0;i<=20;i++)
    {
    mi= rand() % 9999+1000;    
    printf("%d\n",mi);
    }
    return 0;
}



Aucun commentaire:

Enregistrer un commentaire