1#include <iostream>
2#include <ctime>
3#include <cstdlib>
4using namespace std;
5int main()
6{
7 srand(time(0)); // Initialize random number generator.
8
9 cout<<"Random numbers generated between 1 and 10:"<<endl;
10 for(int i=0;i<10;i++)
11 cout << (rand() % 10) + 1<<" ";
12 return 0;
13}
14
1#include <stdio.h> /* NULL */
2#include <stdlib.h> /* srand, rand */
3#include <time.h> /* time */
4
5int Main()
6{
7 int randomNumber;
8
9 /* initialize random seed: */
10 srand (time(NULL));
11
12 /* generate random number between 1 and 10: */
13 randomNumber = rand() % 10 + 1;
14 v1 = rand() % 100; // v1 in the range 0 to 99
15 v2 = rand() % 100 + 1; // v2 in the range 1 to 100
16 v3 = rand() % 30 + 1985; // v3 in the range 1985-2014
17}