0
\$\begingroup\$

I was making a ludo game and there's a rule that your pieces will only open when the 6 will shows up on a dice.

How can I make my dice generate the number 6 more often, without using arrays or vectors? I'm using c++.

\$\endgroup\$
  • 1
    \$\begingroup\$ Why the "without using arrays and vector" constraint? \$\endgroup\$ – Philipp Mar 8 '17 at 12:34
6
\$\begingroup\$

Generate a random number between 1 and some number higher than 6 (7, 8, 9, etc). If the result is higher than 6 treat it as a 6.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

First thing that came up on my mind without using array is re-generating a random number again if it is not 6. You can arrange chances with iteration over re-generation.

But this solution does not perform well if random generation function costs high.

| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.