mark.warren
2019-1-18 11:23:14

Can someone remind me of something. I always have trouble remembering this for some reason. If I have a 50% chance of something happening and I am using a random number, is the check < or <= in the following (&lt; 0.5 (random))


mark.warren
2019-1-18 11:34:00

Doh. That should be the other way around anyway (&lt; (random) 0.5)


diego
2019-1-18 13:30:19

Either (&lt; 0.5 (random)) or (&lt; (random) 0.5) should work. The doc for random says “returns a random inexact number between 0 and 1, exclusive”, so neither 0.0 nor 1.0 are ever returned, so 0.5 is the exact middle point, and should be discarded. So no matter what order you choose, &lt; is strictly speaking the correct operator to use.


diego
2019-1-18 13:30:35

In practice, I don’t think &lt; or &lt;= would make any significant difference.


mark.warren
2019-1-18 14:28:52

@diego Thanks, I realise it won’t make much of a difference, just wondered which was ‘right’. Thanks again.