Bug Report #786

unique random numbers

Added by Ben Rogers over 3 years ago. Updated over 3 years ago.

Status:Closed Start date:
Priority:Normal Due date:
Assignee:Redmine Admin % Done:

0%

Category:Helpers
Target version:2.3
Resolution:wontfix Points:

Description

something simple i created, and i extended the num helper for this, so i thought it may be useful, and decided to submit it as a feature request. basicly, if you want x amount of random numbers within your range, and each number has to be unique, this will provide that for you, it needs some work, like type casting, error checking, but at least the idea is there.

    public static function unique_rand($start, $end, $amount) {
        $random = array();
        while ($amount) {
            $amount--;
            do {
                $random_num = mt_rand($start, $end);
            } while (in_array($random_num, $random));
            $random[] = $random_num;
        }
        return $random;
    }

History

Updated by Woody Gilk over 3 years ago

  • Status changed from New to Closed
  • Resolution set to wontfix

Seems like a corner case to me.

Also available in: Atom PDF