Given a fair coin as input, generate any particular unfair outcome
Perl, 37 42 char

($d/=2)+=rand&gt;.5for%!;print$d/2&lt;pop|0


Takes arbitrary probability as a command line argument. Builds a uniform random number in $d and compares it to the input.

Earlier, 52 char solution

$p=&lt;&gt;;do{$p*=2;$p-=($-=$p)}while$--(.5&lt;rand);print$-