Generate random numbers without repeating a value: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Added alternative implementation which simply shuffles the numbers.) |
|||
Line 143: | Line 143: | ||
@[4, 7, 1, 15, 11, 2, 10, 6, 19, 5, 12, 9, 14, 13, 17, 3, 18, 20, 8, 16] |
@[4, 7, 1, 15, 11, 2, 10, 6, 19, 5, 12, 9, 14, 13, 17, 3, 18, 20, 8, 16] |
||
@[10, 9, 15, 2, 17, 8, 3, 20, 18, 12, 11, 14, 16, 13, 4, 5, 6, 1, 7, 19]</pre> |
@[10, 9, 15, 2, 17, 8, 3, 20, 18, 12, 11, 14, 16, 13, 4, 5, 6, 1, 7, 19]</pre> |
||
=={{header|Perl}}== |
|||
Just shuffle... |
|||
<lang perl>#!/usr/bin/perl |
|||
use strict; # https://rosettacode.org/wiki/Generate_random_numbers_without_repeating_a_value |
|||
use warnings; |
|||
use List::Util qw( shuffle ); |
|||
print "@{[ shuffle 1 .. 20 ]}\n" for 1 .. 5;</lang> |
|||
{{out}} |
|||
<pre> |
|||
9 15 11 14 17 10 13 1 2 7 19 3 6 12 4 16 8 5 18 20 |
|||
20 17 18 6 1 19 14 10 2 7 4 12 8 15 3 16 9 11 5 13 |
|||
4 3 9 15 6 20 14 8 18 5 19 17 1 10 11 16 12 2 13 7 |
|||
17 9 3 15 1 20 7 19 13 8 11 10 6 5 4 14 12 18 16 2 |
|||
13 1 5 18 12 11 3 14 10 9 19 4 20 16 8 6 17 2 7 15 |
|||
</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |