So I want to generate a random number between 0 and 20 and having only a basic knowledge of loops,I figured out that we have to use a rand() function(In python you can easily do it with the rand.random()
function but in C there is a difference).
So I tried using :
#include <stdio.h>
#include <stdlib.h>
int main()
{
int r = rand() % 21;
printf("The random no is: %d", r);
return 0;
}
but all it did was return the same no every time.I understood that we have to use srand() before this.But I can't understand the concept behind it and how to use it.
Aucun commentaire:
Enregistrer un commentaire