I am writing java code to solve a problem with simulated annealing method. I need a method to generate a random true
only with probability exp(a/b) where a
and b
are given parameters.
Thanks.
In order to generate Random boolean in Java, we use the nextBoolean() method of the java. util. Random class. This returns the next random boolean value from the random generator sequence.
The best way to generate random bool is to use the MSB bit. This is actually a standard Bernoulli distribution with probability 1/2 . Save this answer.
If you want to create a random boolean, use this code: var random = new Random(); var randomBool = random.
Assuming that a/b
is the percentage probability of returning true:
public boolean exp(double probabilityTrue)
{
return Math.random() >= 1.0 - probabilityTrue;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With