How to generate effectively a random number that only contains unique digits in Python?
<pre><code>import random

def get_number(size):
  result = [random.randint(1,9)]
  digits = list(range(0,10))
  digits.remove(result[0])
  if(size &gt; 1):
    result += random.sample(digits,size-1)
  return ''.join(map(str,result))

print(get_number(4))
</code></pre>

<p>I solved the problem, but I feel that it's clumsy. 
How can I do this more effectively and more elegant? </p>

<p>Just use shuffle:</p>

<pre><code>import string

x = list(string.digits)
random.shuffle(x)

print int(str(random.choice(range(1, 10))) + "".join(x[:3]))
</code></pre>

python list random