Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6711931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:11:59+00:00 2026-05-26T08:11:59+00:00

First sorry if I should have added this to my earlier question today ,

  • 0

First sorry if I should have added this to my earlier question today, but I now have the below code and am having problems getting things to add up to 100…

use strict;
use warnings;

my @arr = map {int( rand(49) + 1) } ( 1..100 ); # build an array of 100 random numbers between 1 and 49

my @count2;

foreach my $i (1..49) {

my @count = join(',', @arr) =~ m/,$i,/g; #  ???
my $count1 = scalar(@count); # I want this $count1 to be the number of times each of the numbers($i) was found within the string/array.

#  push(@count2, $count1 ." times for ". $i); # pushing a "number then text and a number / scalar, string, scalar" to an array.
 push(@count2, [$count1, $i]); 
}

 #sort @count2 and print the top 7
my @sorted = sort { $b->[0] <=> $a->[0] } @count2;
my $sum = 0;
foreach my $i (0..$#sorted) {  # (0..6)

 printf "%d times for %d\n", $sorted[$i][0], $sorted[$i][1];
  $sum += $sorted[$i][0]; # try to add up/sum all numbers in the first coloum to make sure they == 100

}

print "Generated $sum random numbers.\n"; # doesn't add up to 100, I think it is because of the regex and because the first number doesn't have a "," in front of it
# seem to be always 96 or 97, 93...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:12:00+00:00Added an answer on May 26, 2026 at 8:12 am
    #!/usr/bin/perl
    
    use strict; use warnings;
    use YAML;
    
    my @arr;
    $#arr = 99;
    
    my %counts;
    
    for my $i (0 .. 99) {
        my $n = int(rand(49) + 1);
        $arr[ $i ] = $n;
        ++$counts{ $n };
    }
    
    my @result = map  [$_, $counts{$_}],
                 sort {$counts{$a} <=> $counts{$b} }
                 keys %counts;
    
    my $sum;
    $sum += $_->[1] for @result;
    
    print "Number of draws: $sum\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I probably should have just put all this in one question, sorry for that
first sorry if its a stupid question but im lost a bit. So when
First of all sorry if it's a dumb question (and surely it is), but
First I am sorry about the length of this post, but I wanted to
I have a question that is similar to this SO question , but slightly
I have a question that is similar to this SO question , but slightly
First of all, I'm sorry about the feedback-nature of this question. I'm trying to
First sorry for posting this here.I just got no answer to this question on
Sorry if this question may be simple, but I can't seem to find an
At first sorry my bad English. I want define routing for this url: For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.