rand() function is used to generate a random number.
First it will generate a random number between 0 and 1 and then it will multiply it with the number which is passed as argument in rand() function.So whatever is the argument the number generated will be always less than that number.
Output:
Output:
First it will generate a random number between 0 and 1 and then it will multiply it with the number which is passed as argument in rand() function.So whatever is the argument the number generated will be always less than that number.
Random Numbers less than 5
Program Code:
#! /Perl/bin/perl
$count= 1;
while($count<=20){
$randnum=int(rand(5))+1;
print(int(rand(5)));
print("\n");
$randtotal[$randnum]+=1;
$count++;
}
Program Code:
#! /Perl/bin/perl
$count= 1;
while($count<=20){
$randnum=int(rand(5))+1;
print(int(rand(5)));
print("\n");
$randtotal[$randnum]+=1;
$count++;
}
Random Numbers less than 10
Program Code:
#! /Perl/bin/perl
$count= 1;
while($count<=20){
$randnum=int(rand(10))+1;
print(int(rand(10)));
print("\n");
$randtotal[$randnum]+=1;
$count++;
}
Program Code:
#! /Perl/bin/perl
$count= 1;
while($count<=20){
$randnum=int(rand(10))+1;
print(int(rand(10)));
print("\n");
$randtotal[$randnum]+=1;
$count++;
}
0 comments:
Post a Comment