Random ticket code generator

J (4 bytes)

Couldn't resist.

?~10

In J, if F is dyadic , F~ x is the same as x F x.


J, 5 characters and APL, 8 characters

J

10?10

J has the built-in deal operator (?). Thus, we can take 10 out of 10 (10?10).

APL

1-⍨10?10

APL has the same operator which unfortunately starts with one instead of zero. We are therefore subtracting one from each number (1-⍨X means X-1 due to the commute operator).


Python 2.7 (64 63 57)

Not a chance here compared to the operator heavy languages and due to the lack of default loaded random :) This is the shortest I could come up with;

from random import*
print''.join(sample("0123456789",10))

It creates a range and samples 10 numbers from it without replacement.

(Thanks to @xfix for the shorter import format fix and @blkknght for pointing out my somewhat über complicated sampling range)

Python 2.7 (40)

If you run it from the interactive prompt and can read comma separated, you can shave it to 40, but it feels a bit like breaking the spirit of the rules;

from random import*
sample(range(10),10)

Tags:

Code Golf