0

Is this possible to make a program that show output random number 0 to 5 according their different probability?

7th Aug 2016, 8:23 AM
Lekhraj Singh
Lekhraj Singh - avatar
4 Answers
+ 1
rand(); function is used in order to generate any number... here i set 5 so this code will generate a number from 1-5 here is the code... #include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; int main () { int iSecret; /* generate secret number between 1 and 5: */ iSecret = rand() % 5 + 1; cout<<iSecret; return 0; } i hope it will help you...!
7th Aug 2016, 10:04 AM
Karan Luther
Karan Luther - avatar
+ 1
#include <stdio.h> #include <stdlib.h> #include <time.h> #include<iostream > using namespace std; int main () { int iSecret; /* initialize random speed: */ srand (time(NULL)); /* generate secret number between 1 and 10: */ iSecret = rand() % 10 + 1; cout<<iSecret; return 0; } try this one now.. i checked and i was getting 2 sometimes 4 sometimes 3..
7th Aug 2016, 11:28 AM
Karan Luther
Karan Luther - avatar
+ 1
thanks karan
7th Aug 2016, 11:48 AM
Lekhraj Singh
Lekhraj Singh - avatar
0
this program give output every time same
7th Aug 2016, 10:56 AM
Lekhraj Singh
Lekhraj Singh - avatar