I am wondering what this line of code mean?
b = (gen_rand_uniform()>0.5)?1:0;
The gren_rand_uniform()
is a function to generate random 0 and 1 numbers. However I don't get the meaning for >0.5
and 1:0
.
I know this is supposed to be a basic question, please bear with me.
Thanks!
Best Solution
It's shorthand. In the example you gave, it is equivalent to:
Since
gen_rand_uniform()
probably generates uniformly distributed random numbers between1
and0
, there's a 50% chance of the value being higher than 0.5. Which means there's a 50% chance of getting a1
or a0