We have button. User clicking the button and receive action1
or action2
depended by variable percent_to_action2
(from 0 to 100). The simplest way to give him action1
or action2
is based on rand() % 100
and comparison with percent_to_action2
.
But the problem is that if eg. perfect_to_action = 50
there is no guaranty that after first random action1
user will get action2
(by rand()). I am searching the ways to avoid many repeating actions. Please, suggest how to count more accurately considering the previous event/or all events. with examples and comments. Goal is to avoid excessive number of repeating actions that rund() can give. for example with percent = 50 rand() can give 10/10 action2!
ps. perfect_to_action
can be changed at any time.
pps. sorry for me english.
my code:
int num_rand = (rand() % 100 ) + 1; // from 1 to 100
if ( num_rand <= current_percent_to_action2 )
{
// action 1
} else {} // action2
What I want in examples:
percent = 50: action1 than action2 than action1 than action2 etc.
percent = 33: (first by rand) if first action1 than action1 than action2 than action1 than action1 than action2 etc.