[Question]
  [
A lottery company wants to generate a random lottery ticket number of length 10 characters.
Write a code in any language to create such a number in which every digit comes only once for example `9354716208` in this number all integers from 0 to 9 comes only once. This number should be a random number.
* The generated number should be shown on screen.
* It must be able to generate all permutations of all allowable characters.
* The code is required to be as small as possible (in bytes).
  
[Answer]
##  J (4 bytes)
Couldn't resist.
```
?~10
```
In J, if `F` is dyadic , `F~ x` is the same as `x F x`.
[Answer]
### 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).
[Answer]
**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)
```
[Answer]
**PHP, 29 chars**
`<?=str_shuffle('0123456789');`
With PHP, the closing tag isn't required. But if that's against the rules, then you can replace ; with ?> for 1 net increase.
[Answer]
## Ruby, 18
Run this in `irb`:
```
[*0..9].shuffle*''
```
If you want this to be a stand-alone program, with output to `stdout` (the rules don't seem to *require* this), then add these 4 chars at the start:
```
$><<
```
[Answer]
# PHP - 37 Characters
```
<?=join('',array_rand(range(0,9),10))
```
I had an 18-character solution that should theoretically work but PHP is weird.
Or, if you want an xkcd answer:
```
<?="5398421706" // Chosen by program above; guaranteed to be random ?>
```
EDIT: Thanks xfix, it's now 5 characters shorter and complete.
EDIT AGAIN: [Live example](http://codepad.org/gA8lIBWT).
[Answer]
# Perl 6 (~~18~~ 16 characters)
```
print pick *,^10
```
This generates array containing all random elements (`pick *`) from `0` to `9` and outputs the result (`print`).
Sample output:
```
$ perl6 -e 'print pick *,^10'
4801537269
$ perl6 -e 'print pick *,^10'
1970384265
$ perl6 -e 'print pick *,^10'
3571684902
```
[Answer]
### GolfScript, 12 characters
```
10,{;9rand}$
```
Simply generates the list of digits (`10,`) and sorts it `{...}$` according to some random keys - which yields a random order of the digits.
Examples (try [online](http://golfscript.apphb.com/?c=MTAsezs5cmFuZH0k&run=true)):
```
4860972315
0137462985
```
[Answer]
## R (23 characters)
```
cat(sample(0:9),sep="")
```
Sample output:
```
> cat(sample(0:9),sep="")
3570984216
> cat(sample(0:9),sep="")
3820791654
> cat(sample(0:9),sep="")
0548697132
```
[Answer]
## TI-BASIC, 5 bytes
```
randIntNoRep(1,10
```
[Answer]
**Octave (14)**
```
randperm(10)-1
```
`randperm` unfortunately creates a selection from 1..n, so have to subtract 1 at the end to get 0-9.
[Answer]
# In sql server
```
DECLARE @RandomNo varchar(10)
SET @RandomNo = ''
;WITH num as (
SELECT 0 AS [number]
Union 
select 1
Union 
select 2
Union 
select 3
Union 
select 4
Union 
select 5
Union 
select 6
Union 
select 7
Union 
select 8
Union 
select 9
)
SELECT Top 9 @RandomNo = COALESCE(@RandomNo + '', '') + cast(n.number AS varchar(1))
FROM numbers n
ORDER BY NEWID()
SELECT cast(@RandomNo AS numeric(10,0))
```
# [See Demo](http://www.sqlfiddle.com/#!6/d41d8/13548)
OR something similar (courtesy of @manatwork) using recursion and xml.
```
with c as(select 0i union all select i+1from c where i<9)select i+0from c order by newid()for xml path('')
```
[Answer]
# Javascript (~~79~~ ~~78~~ 68 characters)
Rather than creating an array with the numbers 0-9 and sorting it, I decided to generate random numbers. When it came up with a number that was not already in the array then added it. This repeats ten times and then alerts the output.
`for(a="";!a[9];){~a.indexOf(b=~~(Math.random()*10))||(a+=b)}alert(a)`
[Answer]
## Mathematica, 27
```
Row@RandomSample@Range[0,9]
```
![enter image description here](https://i.stack.imgur.com/ILxLc.png)
[Answer]
## Shell/Coreutils, 23
```
shuf -i0-9|paste -sd ''
```
[Answer]
## JavaScript, 82 characters
**EDIT:** Thanks to [Rob W](https://codegolf.stackexchange.com/users/13882/rob-w), code length is reduced to 90 characters.
**EDIT:** Thanks to [George Reith](https://codegolf.stackexchange.com/users/11182/george-reith), code length is reduced to 82 characters (using for loop).
Pretty straightforward way: pick random element of `[0,1,2,3,4,5,6,7,8,9]` array and append it to the output, then reduce array and replay.
*Old version (106 characters):*
```
a=[0,1,2,3,4,5,6,7,8,9],l=11,t="";while(--l){r=Math.floor(Math.random()*l);t+=a[r];a.splice(r,1);}alert(t)
```
Readable version:
```
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], l = 10,t = "";
while(l--) {
  r = Math.floor(Math.random() * l);
  t += a[r];
  a.splice(r, 1);
}
alert(t);
```
*Better version (90 characters):*
```
a="0123456789".split(t=""),l=11;while(--l)t+=a[r=0|Math.random()*l],a.splice(r,1);alert(t)
```
*Last version (82 characters):*
```
a="0123456789".split(t='');for(l=11;--l;t+=a.splice(0|Math.random()*l,1));alert(t)
```
JSFiddle: <http://jsfiddle.net/gthacoder/qH3t9/>.
[Answer]
# C#, 145 bytes
## Ungolfed
```
using System;
using System.Linq;
class P
{
    static void Main()
    {
        Enumerable.Range(0,10).OrderBy(g => Guid.NewGuid()).ToList().ForEach(Console.Write);
    }
}
```
## Golfed
```
using System;using System.Linq;class P{static void Main(){Enumerable.Range(0,10).OrderBy(g => Guid.NewGuid()).ToList().ForEach(Console.Write);}}
```
[Answer]
# Mathematica 40
The number is created as a string so as to allow zero to be displayed as the first character, when needed.
```
""<>RandomSample["0"~CharacterRange~"9"]
```
**Output examples**
> 
> "0568497231"  
> 
> "6813029574"
> 
> 
> 
**Explanation**
`"0"~CharacterRange~"9"` is infix notation for `CharacterRange["0","9"]`.
Either of these returns the list, `{"0","1","2","3","4","5","6","7","8","9"}`.
`RandomSample[list]` by default returns a permutation of the list. (It can also be used for other kinds of sampling, when parameters are included. E.g. `RandomSample[list, 4]` will return a Random sample of 4 characters, with no repeats.
[Answer]
## K/Kona (6)
```
-10?10
```
As with J, `?` is the deal operator; the `-` forces the values to not repeat.
[Answer]
## Scala, 37
```
util.Random.shuffle(0 to 9).mkString
```
[Answer]
## JavaScript (80 characters)
```
alert("0123456789".split("").sort(function(){return .5-Math.random()}).join(""))
```
JS-Fiddle: <http://jsfiddle.net/IQAndreas/3rmza/>
[Answer]
## Forth, 72
```
needs random.fs : r ': '0 do i loop 9 for i 1+ random roll emit next ; r
```
Room still to golf, maybe, but Forth made this one hard. I think.
[Answer]
# Prolog, 177/302 characters
I'm a beginner on Prolog, so probably this is not the most condensed code.
```
:- use_module(library(clpfd)).
sort(N) :-
    N = [N0,N1,N2,N3,N4,N5,N6,N7,N8,N9],
    domain([N0],1,9),
    domain([N1,N2,N3,N4,N5,N6,N7,N8,N9],0,9),
    all_different(N),
    labeling([],N).
```
Returns:
```
| ?- sort2(N).                                         
N = [1,0,2,3,4,5,6,7,8,9] ? ;
N = [1,0,2,3,4,5,6,7,9,8] ? ;
N = [1,0,2,3,4,5,6,8,7,9] ? ;
N = [1,0,2,3,4,5,6,8,9,7] ? ;
N = [1,0,2,3,4,5,6,9,7,8] ? 
yes
```
If you want it to return an integer:
```
:- use_module(library(clpfd)).
sort(M) :-
    N = [N0,N1,N2,N3,N4,N5,N6,N7,N8,N9],
    domain([N0],1,9),
    domain([N1,N2,N3,N4,N5,N6,N7,N8,N9],0,9),
    all_different(N),
    labeling([],N),
    M is (N0*1000000000)+(N1*100000000)+(N2*10000000)+(N3*1000000)+
         (N4*100000)+(N5*10000)+(N6*1000)+(N7*100)+(N8*10)+N9.
```
Returns:
```
| ?- sort(N).
N = 1023456789 ? ;
N = 1023456798 ? ;
N = 1023456879 ? ;
N = 1023456897 ? ;
N = 1023456978 ? 
yes
```
Using instead:
```
labeling([down],N)
```
Gives the numbers in the opposite order:
```
| ?- sort(N).                                        
N = 9876543210 ? n
N = 9876543201 ? n
N = 9876543120 ? n
N = 9876543102 ? n
N = 9876543021 ? 
yes
```
Unlike some other codes posted, this returns all possibilities (with no repetitions).
[Answer]
# [q/kdb](http://en.wikipedia.org/wiki/Q_%28programming_language_from_Kx_Systems%29) [6 chars]
```
-10?10
```
will generate 10 unique random numbers.
[Answer]
# [√ å ı ¥ ® Ï Ø ¿](https://github.com/ValyrioCode/Valyrio) , 4 bytes
```
XrśO
X    › Push 10 to the stack
 r   › Push the range from [1...10]
  ś  › Shuffle the stack
   O › Output the whole stack separated by spaces
```
[Answer]
**Clojure, 42**
```
(println (apply str (shuffle (range 10))))
```
> 
> 6209847315
> 
> 
> 
[Answer]
# Javascript, 83 characters
```
a=[];while(!a[9]){b=Math.floor(Math.random()*10);!a.includes(b)&&a.push(b)}alert(a)
```
While running until array has 10 elements.
Generating random number from 0 - 9 then check if array !includes this number and add it to the array.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `s`, 4 bytes
```
kdÞ℅
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJzIiwiIiwia2TDnuKEhSIsIiIsIiJd)
Explanation:
```
kd   # Digits `0123456789`
  Þ℅ # Random permutation
     # 's' flag - Print the sum of the top of the stack
```
[Answer]
This is not much smaller than JMK's answer, but here's a slightly smaller C# solution (135):
```
using System;
using System.Linq;
class P { 
    static void Main() 
    { 
        Console.Write(string.Join("", "0123456789".OrderBy(g => Guid.NewGuid()))); 
    } 
}
```
Compacted (134):
```
using System;using System.Linq;class P{static void Main(){Console.Write(string.Join("", "0123456789".OrderBy(g => Guid.NewGuid())));}}
```
Alternate version (135):
```
using System;
using System.Linq;
class P { 
    static void Main() 
    { 
        "0123456789".OrderBy(g => Guid.NewGuid()).ToList().ForEach(Console.Write); 
    } 
}
```
Compacted:
```
using System;using System.Linq;class P{static void Main(){"0123456789".OrderBy(g => Guid.NewGuid()).ToList().ForEach(Console.Write);}}
```
They're equal in length, but it really just depends on whether you want to use Linq's ForEach function or String's Join function. I was able to remove 10 characters in length by spelling out the range "0123456789" in a string instead of using Enumerable.Range(0, 10).
[Answer]
**LOGO**, 64 characters
```
make "d 1234567890
repeat 10 [
    make "n pick d
    show n
    make "d butmember n d
]
```
**pick** returns random item of the supplied list.
**butmember** returns list with all occurrences of the specified item removed.
*Note: Not all Logo implementations support `butmember` command.*
]