Click to See Complete Forum and Search --> : Probability programming


LOGICO
December 20th, 2006, 08:36 AM
Hello

Some action has a 0.1 probability of happening.

This was the solution I got:

0.1 is 10%

We chose a value between 1 and 10 and assign that value to the action.
Then we generate a random number between 0 and 10. If that number is the number set to the "action", the action happens.



/* value between 1 and 10 */
action = 1

rnd = rand ( 1, 10 )

if ( rnd == action ) {
make action
}


Is this a valid solution to get a 0.1 probabily that the action is done?

Thanks for your comment.

TheCPUWizard
December 20th, 2006, 09:23 AM
That the basic idea :)