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 7888091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:44:57+00:00 2026-06-03T05:44:57+00:00

In PHP, if I build a factory inspection program with a conveyor belt where

  • 0

In PHP, if I build a factory inspection program with a conveyor belt where the popdown listbox on the form is 100% (inspect nothing — let all go through) to 0% (inspect everything), what is the function to calculate when one of the widgets is due for inspection?

A little extra info — the label says “Let [x%] widgets go through without inspection”.

More than this, how can we test your algorithm to prove it’s correct? For instance, a value of 100%, run 99999 times, should show no inspections. A value of 99%, run 99999 times, should maybe show one inspection in a blue moon if run repeatedly. A value of 0%, run 99999 times, should show all 99999 widgets being sent to inspection.

EDIT: A coworker says I’m getting odds and probability mixed up here. She thinks I’m describing probability?

Anyway, I tried this code as a test, but it doesn’t do anything except at the 100, and 50 through 1 marks. However, the 1-49 act like the 50, while the 51 through 100 act like 100.

<?php

$nChance = @ $argv[1];
$nChance = intval($nChance);

for ($i = 1; $i <= 999999; $i++) {
  $nTest = rand(1,floor(100/$nChance));
  if (!($nTest == 1)) {
    die("INSPECT! i($i) rand($nTest) chance($nChance)\n");
  }
}

I then tried this variation and that failed too because it simply said INSPECT all the time.

<?php

$nChance = @ $argv[1];
$nChance = intval($nChance);

for ($i = 1; $i <= 999999; $i++) {
  $nTest = rand(0,100);
  if (!($nTest < $nChance)) {
    die("INSPECT! i($i) rand($nTest) chance($nChance)\n");
  }
}
  • 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-03T05:44:58+00:00Added an answer on June 3, 2026 at 5:44 am
    $nChance = 5; // % chance of inspection
    $x       = 1; // number of seconds between products passing inspection point
    while ( isLineRunning() )
    {
        if( mt_rand(1,100) <= $nChance )
        {
            echo "INSPECT ITEM!";
        }
        sleep( $x );
    };
    

    this would check every ‘x’ seconds while the line is running.

    Your colleague is kind of correct but for your purposes you are making a decision based on whether a random number is less than or equal to (in this case) 5 which if truly random (which its not when generated like this) should deliver a 1 in 20 chance you select any given item.

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

Sidebar

Related Questions

I'm using php to build a small form that requires passing 2 variables for
I build PHP for android using the NDK. Most functions tested so far run
I am installing a pre-build php-based web application for a client. Unfortunately the application
I am using MySQL and PHP to build a data layer for a flash
I'm using the DOM extension in PHP to build some HTML documents, and I
I'm using a combination of PHP and Phonegap. I use PHP to build the
I have a web application build on PHP that (does some processing and) displays
I'm using CodeIgniter (a PHP framework) to build an app, and I have an
I build a css file using PHP which allows me to easily customize the
I am using PHP and jQuery to build an interactive timeline which needs to

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.