Does anyone have a quick way to randomly return either 1 or -1?
Something like this probably works, but seems less than ideal:
return Random.nextDouble() > .5 ? 1 : -1;
how about:
random.nextBoolean() ? 1 : -1;
where random
is an instance of java.util.Random
return Random.nextInt(2) * 2 - 1;
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