MrASquare
0
Q:

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.
3
//Remember to use srand() between
//rand()'s to change the seed:

#include <cstdlib>
#include <ctime>

std::srand(time(NULL));

int variable = rand();
1
srand(time(NULL));
  int r = rand();
0
#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;
      }
    }
}
-2

New to Communities?

Join the community