<random>
これにはライブラリを使用する必要があります。
#include <random>
#include <iostream>
#include <algorithm>
#include <iterator>
int main() {
// create a discrete distribution where the third object has 20% probability and
// the seventh has 30%
std::vector<double> probabilities(10, 5.0/8.0);
probabilities[2] = 2.0;
probabilities[6] = 3.0;
std::discrete_distribution<int> dist(begin(probabilities),end(probabilities));
// our underlying source of randomness
std::random_device r;
std::seed_seq seed{r(), r(), r(), r(), r(), r(), r(), r()};
std::mt19937 eng(seed);
// create a function object that uses the distribution and source of randomness to
// produce values from 1 to 10
auto rand = [&]{ return dist(eng) + 1; };
std::vector<int> x;
// store 1000 random values
for (int i=0;i<1000;++i)
x.push_back(rand());
// count how many of each value, to verify that 3 comes out ~200 times and 7 comes
// out ~300 times
for (int i=1;i<=10;++i)
std::cout << i << ": " << count(begin(x),end(x),i) << '\n';
// print all the values
copy(begin(x),end(x),std::ostream_iterator<int>(std::cout, " "));
}