Permalink
Browse files

oops: Fix randNumber()

This addresses an issue where the `randNumber()` function would crash on
32-Bit systems if the ticket format was set to a really high amount of
digits (eg. ###################). This is because the `max()` value that
was being passed to `mt_rand()` exceeded the `mt_getrandmax()` limit which
caused an error. This updates the function to generate a random number for
each digit to avoid the `mt_getrandmax()` limit.
  • Loading branch information...
JediKev committed Feb 21, 2018
1 parent c4669d7 commit 5b8b95ab8d70b73f3f97af74e174a23877496c87
Showing with 7 additions and 5 deletions.
  1. +7 −5 include/class.misc.php
View
@@ -52,12 +52,14 @@ function __rand_seed($value=0) {
}
/* Helper used to generate ticket IDs */
function randNumber($len=6,$start=false,$end=false) {
$start=(!$len && $start)?$start:str_pad(1,$len,"0",STR_PAD_RIGHT);
$end=(!$len && $end)?$end:str_pad(9,$len,"9",STR_PAD_RIGHT);
function randNumber($len=6) {
$number = '';
for ($i=0; $i<$len; $i++) {
$min = ($i == 0) ? 1 : 0;
$number .= mt_rand($min, 9);
}
return mt_rand($start,$end);
return (int) $number;
}
/* misc date helpers...this will go away once we move to php 5 */

0 comments on commit 5b8b95a

Please sign in to comment.