Skip to main content
added 1 character in body
Source Link
pxeger
  • 25.3k
  • 4
  • 59
  • 146

Zsh, 19 bytes

grep -oam1 x /*/ur*

Attempt This Online!

Explanation:

  • /*/ur*: glob for /dev/urandom, a randoman infinite stream of random bytes
  • grep x: search for the letter x
  • -o: print only the letter xs
  • -a: force output even though /dev/urandom is a binary file
  • -m1: quit after the first matching line

Pure Zsh, 20 bytes

for ((;RANDOM;))<<<x

Attempt This Online!

Loop breaks with probability \$ \frac 1 {32768} \$ for each iteration.

Explanation:

  • for ((;RANDOM;)): loop while $RANDOM (which is a random integer in the range \$ [0, 32768) \$, is nonzero
  • <<<x: print x

Here's a version for 2 bytes more with a probability of \$ \frac 1 2 \$, and is much more easy to demonstrate:

for ((;RANDOM%2;))<<<x

Attempt This Online!

Zsh, 19 bytes

grep -oam1 x /*/ur*

Attempt This Online!

Explanation:

  • /*/ur*: glob for /dev/urandom, a random infinite stream of bytes
  • grep x: search for the letter x
  • -o: print only the letter xs
  • -a: force output even though /dev/urandom is a binary file
  • -m1: quit after the first matching line

Pure Zsh, 20 bytes

for ((;RANDOM;))<<<x

Attempt This Online!

Loop breaks with probability \$ \frac 1 {32768} \$ for each iteration.

Explanation:

  • for ((;RANDOM;)): loop while $RANDOM (which is a random integer in the range \$ [0, 32768) \$, is nonzero
  • <<<x: print x

Here's a version for 2 bytes more with a probability of \$ \frac 1 2 \$, and is much more easy to demonstrate:

for ((;RANDOM%2;))<<<x

Attempt This Online!

Zsh, 19 bytes

grep -oam1 x /*/ur*

Attempt This Online!

Explanation:

  • /*/ur*: glob for /dev/urandom, an infinite stream of random bytes
  • grep x: search for the letter x
  • -o: print only the letter xs
  • -a: force output even though /dev/urandom is a binary file
  • -m1: quit after the first matching line

Pure Zsh, 20 bytes

for ((;RANDOM;))<<<x

Attempt This Online!

Loop breaks with probability \$ \frac 1 {32768} \$ for each iteration.

Explanation:

  • for ((;RANDOM;)): loop while $RANDOM (which is a random integer in the range \$ [0, 32768) \$, is nonzero
  • <<<x: print x

Here's a version for 2 bytes more with a probability of \$ \frac 1 2 \$, and is much more easy to demonstrate:

for ((;RANDOM%2;))<<<x

Attempt This Online!

added 422 characters in body
Source Link
pxeger
  • 25.3k
  • 4
  • 59
  • 146

Zsh, 19 bytes

grep -oam1 x /*/ur*

Attempt This Online!

Explanation:

  • /*/ur*: glob for /dev/urandom, a random infinite stream of bytes
  • grep x: search for the letter x
  • -o: print only the letter xs
  • -a: force output even though /dev/urandom is a binary file
  • -m1: quit after the first matching line

Pure Zsh, 20 bytes

for ((;RANDOM;))<<<x

Attempt This Online!

Loop breaks with probability \$ \frac 1 {32768} \$ for each iteration.

Explanation:

  • for ((;RANDOM;)): loop while $RANDOM (which is a random integer in the range \$ [0, 32768) \$, is nonzero
  • <<<x: print x

Here's a version for 2 bytes more with a probability of \$ \frac 1 2 \$, and is much more easy to demonstrate:

for ((;RANDOM%2;))<<<x

Attempt This Online!

Zsh, 19 bytes

grep -oam1 x /*/ur*

Attempt This Online!


Pure Zsh, 20 bytes

for ((;RANDOM;))<<<x

Attempt This Online!

Loop breaks with probability \$ \frac 1 {32768} \$ for each iteration.

Here's a version for 2 bytes more with a probability of \$ \frac 1 2 \$, and is much more easy to demonstrate:

for ((;RANDOM%2;))<<<x

Attempt This Online!

Zsh, 19 bytes

grep -oam1 x /*/ur*

Attempt This Online!

Explanation:

  • /*/ur*: glob for /dev/urandom, a random infinite stream of bytes
  • grep x: search for the letter x
  • -o: print only the letter xs
  • -a: force output even though /dev/urandom is a binary file
  • -m1: quit after the first matching line

Pure Zsh, 20 bytes

for ((;RANDOM;))<<<x

Attempt This Online!

Loop breaks with probability \$ \frac 1 {32768} \$ for each iteration.

Explanation:

  • for ((;RANDOM;)): loop while $RANDOM (which is a random integer in the range \$ [0, 32768) \$, is nonzero
  • <<<x: print x

Here's a version for 2 bytes more with a probability of \$ \frac 1 2 \$, and is much more easy to demonstrate:

for ((;RANDOM%2;))<<<x

Attempt This Online!

Source Link
pxeger
  • 25.3k
  • 4
  • 59
  • 146

Zsh, 19 bytes

grep -oam1 x /*/ur*

Attempt This Online!


Pure Zsh, 20 bytes

for ((;RANDOM;))<<<x

Attempt This Online!

Loop breaks with probability \$ \frac 1 {32768} \$ for each iteration.

Here's a version for 2 bytes more with a probability of \$ \frac 1 2 \$, and is much more easy to demonstrate:

for ((;RANDOM%2;))<<<x

Attempt This Online!