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

  • SEARCH
  • Home
  • 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 8234785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:35:57+00:00 2026-06-07T18:35:57+00:00

In my program, the average value of $integers[0]->occurences should be 20000.Why it’s always larger

  • 0

In my program, the average value of $integers[0]->occurences should be 20000.Why it’s always larger than 20000, even after using srand()?

<?php 
        define('NUM_OF_INTS',49);    
        define('DRAWS',1000000);

            class number
            {
               public $occurences;
               public $value;

               function number()                     
               {
                   $occurences=0;
                   $value=0;
               }
            }

            $integers = array();

            //srand(time(0));
            //initialising loop
            for($i=0;$i<=NUM_OF_INTS;$i++)
            {    
                $integers[$i] = new number(); 
                $integers[$i]->value = $i;

            }
            for($i=0;$i<DRAWS;$i++)
            {                  
                $integers[rand(0,NUM_OF_INTS)]->occurences++;               
            }

            foreach($integers as $int)
                printf("%5d %5d  <br/>",$int->value,$int->occurences);
        ?>
  • 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-06-07T18:35:59+00:00Added an answer on June 7, 2026 at 6:35 pm

    You say that you’re using WAMP.

    PHP’s rand() isn’t very random on Windows (it only generates 15 bits of randomness) so it’s unable to distribute its random numbers evenly enough between the 50 bins.

    In particular, bin 0 will receive 656 / 32768 of the random numbers, which is about 0.0200195

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The program below should read in a bunch of integers from a file and
A simple java program to input the name of student and find the average
Program that calculates and shows the value of (2 to the 10th power) This
program to output all 4 digit numbers where no prior digit is greater than
so I'm trying to make a program that will output the sum, average, and
I built a little program that calculates the average of 15 numbers or less.
Im implementing ITU standard based loudness measurement program and as it states i should
I am trying to log the average running time of 10 threads by using
i want to create a program which calculates the average of N random numbers
I have a program that outputs reports in HTML format. On average, they are

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.