MATL, 5 bytes
Three different versions of this one, all length 5.
iYr1=
which takes an input (i
), generates a random integer between 1 and that number (Yr
), and sees if it it is equal to 1 (1=
). Alternatively,
li/r>
make a 1 (l
, a workaround because there is a bug with doing 1i
at the moment), take an input (i
), divide to get 1/N (/
), make a random number between 0 and 1 (r
), and see if the random number is smaller than 1/N. Or,
ir*1<
take and input (i
), and multiply by a random number between 0 and 1 (r*
), and see if the result is smaller than 1 (1<
).
In Matlab, not MATL, you can do this anonymous function
@(n)n*rand<1
for 12 bytes, which is used by doing ans(5)
, for example.