Generate random numbers without repeating a value: Difference between revisions

Line 864:
 
=={{header|Python}}==
===Version 1===
<syntaxhighlight lang="python">
import random
 
print(random.sample(range(1, 21), 20))
</syntaxhighlight>
</syntaxhighlight>{{out}}[14, 15, 3, 18, 4, 11, 16, 10, 12, 20, 13, 1, 6, 7, 2, 17, 5, 9, 19, 8]
{{out}}
<pre>
</syntaxhighlight>{{out}}[14, 15, 3, 18, 4, 11, 16, 10, 12, 20, 13, 1, 6, 7, 2, 17, 5, 9, 19, 8]
</pre>
 
===Version 2===
<syntaxhighlight lang="python">
import random as r
 
def GenerateRandomSet(n: int) -> list:
set_ = list(range(1, n+1))
r.shuffle(set_)
return set_
</syntaxhighlight>
 
=={{header|Quackery}}==