Is there a method that allows me to generate a boolean based on some percentages?
For example, I need a generator that has a 25% chance of giving me false information.
Now I am doing:
val rand = new Random()
val a = List(true,true,true,false)
val isFailure = a(rand.nextInt(4))
I do this to get my “25%” chance of failure, but I'm not sure if this is the right way, and I’m sure there is a better way.
Can someone direct me where to look or how to do it?
source
share