develooper Front page | perl.beginners | Postings from May 2008

Re: generating number ranges using rand function

Thread Previous
From:
Gunnar Hjalmarsson
Date:
May 4, 2008 08:54
Subject:
Re: generating number ranges using rand function
Aruna Goke wrote:
> I have worked on the code below and am able to generate the 15digit 
> lenght required .
> 
> However, what i wish to achieve is to make sure all the output comes out 
> in 15 digits each. a sample of my output is as below.
> 
> Can someone guide on how to make all come out in 15digits.
> 
> Thank you.
> 
> Goksie
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> use Perl6::Say;
> 
> # make a subrouting to generate random numbers;
> my ($ab, $ac, $ad, $a, $b, $c, $d);
> sub pin_number($$$){
> ($b, $c, $d) = @_;
> for($a=0; $a<=10; $a++){
> $ab = int(rand($b));
> $ac = int(rand($c));
> $ad = int(rand($d));
> say $ab, $ac, $ad;
> }
> 
>  }
> pin_number(99999,99999,99999);
> 
> _OUTPUT_
> 737027546660830
> 4806662848095
> 88295762678621
> 823446006493218
> 459372786221944
> 897977689470748
> 924616140070650
> 897575667638802
> 269285958818874
> 740564487266857
> 17098933279094

So you want a random number between 100_000_000_000_000 and 
999_999_999_999_999, right? Then why not just follow the example in the 
FAQ entry

     perldoc -q "get a random number"

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Thread Previous


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About