diff options
| -rw-r--r-- | challenge-246/adam-russell/perl/ch-1.pl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-246/adam-russell/perl/ch-1.pl b/challenge-246/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..b462c6e959 --- /dev/null +++ b/challenge-246/adam-russell/perl/ch-1.pl @@ -0,0 +1,22 @@ +use v5.38; +## +# 6 out of 49 is a German lottery. +# Write a script that outputs six unique random integers from the range 1 to 49. +## +package SixOfFourtyNine{ + use Math::Random::Secure q/irand/; + sub pick_six{ + my @six; + { + my $r = irand(49) + 1; + push @six, $r if 0 == grep {$_ == $r} @six; + redo unless @six == 6; + } + return sort {$a <=> $b} @six; + } + +} + +package main{ + say join q/, /, SixOfFourtyNine::pick_six; +} |
