0
Is this possible to make a program that show output random number 0 to 5 according their different probability?
4 Antworten
+ 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...!
+ 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..
+ 1
thanks karan
0
this program give output every time same