random en c
snippet in c

how to genrate a random number in C

user6185

#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.

rand()

user1048

//Remember to use srand() between
//rand()'s to change the seed:

#include <cstdlib>
#include <ctime>

std::srand(time(NULL));

int variable = rand();

how to genrate a random number in C

user3889

srand(time(NULL));
  int r = rand();

how to get random numbers in c

user7107

#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;
}

random en c

user9298

#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;
      }
    }
}