random en c
#include <time.h>
#include <stdlib.h>
srand(time(NULL)); // Initialization, should only be called once.
int r = rand(); // Returns a pseudo-random integer between 0 and RAND_MAX.srand(time(NULL));
int r = rand();#include <stdio.h>
int main(){
int i = 0;
while(i < 50)
{
int num;
num = rand(); //this function generates the random number
printf("%i\n", num);
i++;
}
return 0;
}//Remember to use srand() between
//rand()'s to change the seed:
#include <cstdlib>
#include <ctime>
std::srand(time(NULL));
int variable = rand();#include <time.h>
#include <stdlib.h>
//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
#define kFIL 3
#define kCOL 5
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;
}
}
}