Skip navigation
Currently Being Moderated

Is Rand not random at all?

Jun 26, 2013 11:51 PM

Tags: #php #random #rand #answers #flips

I was playing around tonight and came up with the following:

 

<?php
    $myNumber = 0;
    $numberFlip = 0;
    while ($myNumber < 9) {
        $roll = rand(0,2);
        $numberFlip ++;
             if ($roll == 1) {
                 $myNumber ++;
            }
            elseif ($roll == 0) {
                $myNumber = 0;
            }
            else {
                $myNumber = 0;
            }
                        }
    echo "<p>It took {$numberFlip} flips!</p>"
    ?>

 

The issue is - each time I refresh the page -  it only gives a possibility of a couple answers and then it keeps cycling through those answers repeatedly in order.  (4,008 flips, 8,922, 1,421, 452, 18,417)

 

Why on earth would it do that?   Shouldn't it be more random than that?

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points