in reply to Generate a # between 1 and 50 in groups of 5
Random numbers can be generated using rand() function (see rand). This short script below prints 5 random numbers between 1 and 50. The group of numbers is sorted.
#!/usr/bin/perl -w use strict; my %num; while ((keys %num) < 5) { $num{int(rand(50)+1)} = 1; } print join(' ' , sort {$a <=> $b} keys %num) . "\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Generate a # between 1 and 50 in groups of 5
by Hayest (Acolyte) on Feb 04, 2015 at 15:27 UTC | |
by LanX (Saint) on Feb 04, 2015 at 16:15 UTC |