Skip to main content
removed name
Source Link
Alex A.
  • 24.7k
  • 5
  • 38
  • 119

Julia, 17 1616 15 bytes

f(n)=2>rand->2>rand(1:n)

This is a function that generates a random integer between 1 and n and tests whether it's less than 2. There will be a 1/n chance of this happening, and thus a 1/n chance of returning true.

Saved 1 byte thanks to Thomas Kwa!

Julia, 17 16 bytes

f(n)=2>rand(1:n)

This is a function that generates a random integer between 1 and n and tests whether it's less than 2. There will be a 1/n chance of this happening, and thus a 1/n chance of returning true.

Saved 1 byte thanks to Thomas Kwa!

Julia, 17 16 15 bytes

n->2>rand(1:n)

This is a function that generates a random integer between 1 and n and tests whether it's less than 2. There will be a 1/n chance of this happening, and thus a 1/n chance of returning true.

Saved 1 byte thanks to Thomas Kwa!

added 91 characters in body
Source Link
Alex A.
  • 24.7k
  • 5
  • 38
  • 119

Julia, 1717 16 bytes

f(n)=n==rand=2>rand(1:n)

This is a function that generates a random integer between 1 and n and tests for equality with nwhether it's less than 2. There will be a 1/n chance of this happening, and thus a 1/n chance of returning true.

Saved 1 byte thanks to Thomas Kwa!

Julia, 17 bytes

f(n)=n==rand(1:n)

This is a function that generates a random integer between 1 and n and tests for equality with n. There will be a 1/n chance of returning true.

Julia, 17 16 bytes

f(n)=2>rand(1:n)

This is a function that generates a random integer between 1 and n and tests whether it's less than 2. There will be a 1/n chance of this happening, and thus a 1/n chance of returning true.

Saved 1 byte thanks to Thomas Kwa!

Source Link
Alex A.
  • 24.7k
  • 5
  • 38
  • 119

Julia, 17 bytes

f(n)=n==rand(1:n)

This is a function that generates a random integer between 1 and n and tests for equality with n. There will be a 1/n chance of returning true.