Wouldn't `mt_rand(pow(10, $nbDigits - 1), pow(10, $nbDigits) - 1);` do the job as well?