Skip to main content
2 of 3
added 9 characters in body
jimmy23013
  • 37k
  • 6
  • 77
  • 148

#Bash, 66

LANG=C sed -r '/^-?(0|[1-9][0-9]*)$/q;s/.*/5000000/;q'</dev/random

It almost always prints 5000000. But if it found a valid number in /dev/random, it will print that number instead.

And this one is faster:

LANG=C sed -r '/^-?(0|[1-9][0-9]*)$/q;s/.*/5000000/;q'</dev/urandom
jimmy23013
  • 37k
  • 6
  • 77
  • 148