I haven't written c++ in a long time, but it would go something like this (comments included).double x; // declare your variableint r = rand(99); // get a random integer 0-99if (r>34) x = 1; // 65/100 chanceelse x = 2; // 35/100 chanceReplace 1 and 2 with whatever the numbers are.Actually you might be able to shorten that using the ternary operator.double x = (rand(99) > 34) ? 1 : 2;Yeah that's a way more elegant solution.
|