how to use time() function for random generator in c code example
Example 1: random number generator c
rand() % (maxlimit + 1 - minlimit) + minlimit;
Example 2: random en c
//con vectores
void random(int tam){
int v[tam];
srand(time(NULL));
for(int i = 0; i <= tam; i++){
v[i] = rand() % 10;
//v[i] = rand()%5; //Con el 5, son numeros desde 0 a 5
printf("v[%d] = %d\n", i, v[i]);
}
}
//Con matrices
typedef int TMatriz [kFIL][kCOL];
void random(TMatriz m){
int i, j;
srand(time(NULL));
for( i = 0; i < kFIL; i++){
for(j = 0; j < kCOL; j++){
m[i][j] = rand() % 100;
}
}
}