Friday, April 7, 2017

Random Value Generator in C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*  Bismillahir Rahmanir Rahim
    Random Value Generating
    Input any integer(n).
*/
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
     int n;
     while(cin>>n){// for understanding the output clearly
         cout<<"Random value (any integer)   = "<<rand()<<endl;
         cout<<"Random value (from 0 to 9)   = "<<rand()%10<<endl;
         cout<<"Random value (from 1 to 100) = "<<rand()%100+1<<endl;
         cout<<"Random value (from 3 to 8)   = "<<rand()%6+3<<endl;
     }
     return 0;
}

No comments:

Post a Comment