in reply to Generate a # between 1 and 50 in groups of 5

Hi Hayest, welcome to the monastery.

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
    pme,

    This is exactly what I was looking to do. Now we are tasked with something additional: "Sum each group and display the results so that each number is on its own line." How would I go about doing something like this? Would I need to implement some sort of do/while or for/next loop?

    Thank you in advance!
      > How would I go about doing something like this?

      perlintro is a good entry point to learn programing!

      Cheers Rolf

      PS: Je suis Charlie!