get random nuber in c++ code example
Example 1: c++ generate random numbers
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(0));
for (int i = 0; i <= 10; i++)
{
cout << rand() % 10 << " ";
}
}
Example 2: random in c++
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
int num;
srand(time(0));
num = rand() % 10 + 1;
cout << num << endl;
}