Russian Roulette
PHP 38 bytes
<?~$$s[rand(+$s=sssss,5)]?>I survived!
Placing a +
before a non-numeric string will evaluate to 0
. Should rand(0,5)
return 5
, $s[rand(0,5)]
will be the empty string (since $s
is only five characters long), and subsequently $$s[rand(0,5)]
will be an uninitialized variable. Attempting to take the inversion will halt on Unsupported Operand Type. Any other value, 0-4
will return s
, and because $s
is defined, you will survive.
Note: as of php version 4.2.0, the random number generator is seeded automatically.
Dyalog APL - 25 22 21 20 Charachters
'I Survived!'⊣1÷6⊤?6
Prints DOMAIN ERROR
as the error, due to division by zero.
Shortest non-division by zero solution I could come up with is 23 characters.
('I Survived!'1)[~6⍷?6]
It throws an INDEX ERROR
Try it here
APL Font here
R 30
"I survived!"[6*runif(1)<5||Z]
One time out of six, it will throw an error: Error: object 'Z' not found