Reputation: 4275
If i have a uniformly distributed random variable in [0,1), how can i modify it (only using arithmetic expressions) s.t. it is -1 with probability 1/2 and 1 with probability 1/2?
Upvotes: 1
Views: 357
Reputation: 2120
If your random variable is less than 0.5, map it to -1, otherwise map it to 1.
Edit: If you allow using absolute value, you can do (x - 0.5) / abs(x - 0.5).
Upvotes: 0
Reputation: 16441
If floor (or conversion to nearest integer below x) is OK:
floor(x*2)*2-1
With rounding to the nearest integer:
round(x*2-0.5)*2-1
Upvotes: 1