MATLAB: Generating random variable between 0 and 1 with probabilities

generating random variable between 0 and 1 with probabilitiesMATLAB

Hi all,
I have two questions please:
1) how do i generate a random number either 0 or 1 with equal chances of accept and reject 50-50 chance?
2) how do i generate a random number either 0 or 1 with percent shift in probablity in order to accept "bias' between -0.5 and 0.5
if percent shift=0 then 50-50 chance of accept
if percent shift=0.1 then 60% accept – 40% reject
if percent shift=0.2 then 70% accept – 30% reject
if percent shift=0.3 then 80% accept – 20% reject
if percent shift=0.4 then 90% accept – 20% reject
if percent shift=0.5 then 100% accept – 0% reject
if percent shift=-0.1 then 40% accept – 60% reject
if percent shift=-0.2 then 30% accept – 70% reject
if percent shift=-0.3 then 20% accept – 80% reject
if percent shiftt=-0.4 then 10% accept – 90% reject
if percent shift=-0.5 then 0% accept – 100% reject
Thanks!

Best Answer

rand() < (percent_shift + 0.5)