Hello Friends,
I am doing randomization of intergers for specific range.The way i have done is mentioned below.
Here my problem is i am not getting the random values with in the given range, see the code which i got output for the program, idx2 value is 2, but the range i have mentioned is 4..28.
Please anyone let me know where i did wrong.
Thanks
Raghavendra
I am doing randomization of intergers for specific range.The way i have done is mentioned below.
Code:
use strict;
my @id;
my $idx1;
my $idx2;
my $idx3;
my $idx4;
@id = (4..28);
print ("ID range is @id \n");
$idx1 = int(rand @id );
print ("idx1 random is $idx1 \n");
$idx2 = int(rand @id);
print ("idx2 random is $idx2 \n");
$idx3 = int(rand @id);
print ("idx3 random is $idx3 \n");
$idx4 = int(rand @id);
print ("idx4 random is $idx4 \n");
Code:
[U]Output:[/U] ID range is 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 idx1 random is 10 idx2 random is 2 idx3 random is 14 dx4 random is 13
Please anyone let me know where i did wrong.
Thanks
Raghavendra
Comment