Perl, 7674 chars
Run with perl -M5.010
.
$-=rand 6;$_="-----\n|0
|0 2|\n|4";s2|
|4";s/\d/$->$&?o:$"/ge;say$_,$-&1?$":o,~~reverse
(Note that the newlines in the listing are part of the string, and not just inserted for legibility.)
If you find yourself wondering what the heck the $->$
operation does, the following reading notes may be helpful:
The variable
$-
automatically truncates its assigned value to an integer.The variable
$"
is preset to a single space.o
is a bareword (representing"o"
).