Javacodeman113 Javacodeman113 - 1 month ago 14
Java Question

I want to return a value of true or false but force it to randomly return false 3% of the time

From user input of either char a or char b as an answer.
I want to return a value of true or false from user input.
Then count the number of selections between two possibilities per individual user input.
Then force it to randomly return false 3% of the time.
The purpose is to alter the expected outcome with a reward.

How do I go about doing this? I am new to this concept.

Answer

Check out Math.random(), which gives you a random number [0,1). You want false 3/100 times, so if you multiply your random number by 100, your range will become [0, 100). Then just check if the random number is less than 3, if so, return false.

Comments