I want to generate 10 random numbers in c++ between 1 and 3 inside a loop such that 1 comes the most times (say 50% times), then 2 (30% times) and then 3(20% times). Is it possible to do so?
I have made the following code to get the random numbers between 1 and 3 but how will I add the probabilities?
#include <iostream>
#include <windows.h>
#include "time.h"
int main(int argc, char*argv[])
{
srand ( time(NULL) );
for (int t = 0; t < 10; t++)
{
int random_x;
random_x = rand() % 3+1;
std::cout << "\nRandom X = " << random_x << std::endl;
}
Sleep(50000);
return 0;
}