JavaScript (169 168 141141 137)
r=1+Mathr=Math.random()*6|0;s='-----\n|'+(r>1r>0?'o ':' ')+(r>3r>2?'o':' ')+'|\n|'+(r-65?' ':'o');alert(s+(r%2-1?' ':'o')+s.split('').reverse().join(''))
Doesn't look quite right in alert
because it's not fixed-width font, but rest assured it is correct, or test by emitting a <pre>
tag and doing writeln
:-)
jsfiddle appears to be down currently, so I can't update itProof: http://jsfiddle.net/d4YTn/3/ (only works in JS 1.7-compliant browsers, such as FF2+)
Credits: Hacked Math
trick from @minitech and die print logic from @Keith.
Edit: Remove Math
trick from @minitech because it actually made it longer :-)
Edit 2: Save 17 chars. Borrow trick from @Keith for taking advantage of dice symmetry. Use trick for simplifying converting random numbenumber to int.
Edit 3: Remove 1+
to shift random number from 1-6 to 0-5 and save 2 chars. As a result, I can also change r%2-1
to r%2
and save another 2 chars.
Edit 4: jsfiddle is working again. Updated :-)