Konstantin
0
Q:

rand()

#include <cstdlib>
#include <iostream>
#include <ctime>
 
int main() 
{
    std::srand(std::time(nullptr)); // use current time as seed for random generator
    int random_variable = std::rand();
    std::cout << "Random value on [0 " << RAND_MAX << "]: " 
              << random_variable << '\n';
}
6
you can use rand() function for that in php.
Example:
Generate random numbers between 1 to 50
<?php
  echo rand(1,50);
?>
1
<?php
  echo rand(1,50);
?>
2
//Remember to use srand() between
//rand()'s to change the seed:

#include <cstdlib>
#include <ctime>

std::srand(time(NULL));

int variable = rand();
1
v1 = rand() % 100;         // v1 in the range 0 to 99
v2 = rand() % 100 + 1;     // v2 in the range 1 to 100
v3 = rand() % 30 + 1985;   // v3 in the range 1985-2014 
10
/* rand example: guess the number */
#include <stdio.h>      /* printf, scanf, puts, NULL */
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

int main ()
{
  int iSecret, iGuess;

  /* initialize random seed: */
  srand (time(NULL));

  /* generate secret number between 1 and 10: */
  iSecret = rand() % 10 + 1;

  do {
    printf ("Guess the number (1 to 10): ");
    scanf ("%d",&iGuess);
    if (iSecret<iGuess) puts ("The secret number is lower");
    else if (iSecret>iGuess) puts ("The secret number is higher");
  } while (iSecret!=iGuess);

  puts ("Congratulations!");
  return 0;
}
3
rand() % (max_number + 1 - minimum_number) + minimum_number
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
printf("%d",variable);
-1

New to Communities?

Join the community