{"record":{"id":"098bdbd5c21fc390","repo":"phalcon/cphalcon","slug":"input-number-must-be-a-positive-integer","errorCode":null,"errorMessage":"Input number must be a positive integer","messagePattern":"Input number must be a positive integer","errorType":"exception","errorClass":"InvalidRandomInput","httpStatus":null,"severity":"error","filePath":"phalcon/Encryption/Security/Random.zep","lineNumber":274,"sourceCode":"    }\n\n    /**\n     * Generates a random number between 0 and $len\n     *\n     * Returns an integer: 0 <= result <= $len.\n     *\n     *```php\n     * $random = new \\Phalcon\\Encryption\\Security\\Random();\n     *\n     * echo $random->number(16); // 8\n     *```\n     * @throws Exception If secure random number generator is not available,\n     *                   unexpected partial read or $len <= 0\n     */\n    public function number(int len) -> int\n    {\n        if unlikely len <= 0 {\n            throw new InvalidRandomInput();\n        }\n\n        return random_int(0, len);\n    }\n\n    /**\n     * Generates a v4 random UUID (Universally Unique IDentifier)\n     *\n     * The version 4 UUID is purely random (except the version). It does not\n     * contain meaningful information such as MAC address, time, etc. See RFC\n     * 4122 for details of UUID.\n     *\n     * Delegates to `Phalcon\\Encryption\\Security\\Uuid::v4()`. For other UUID\n     * versions or object-based access use that class directly.\n     *\n     *```php\n     * $random = new \\Phalcon\\Encryption\\Security\\Random();\n     *","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Encryption/Security/Random.zep#L256-L292","documentation":"Thrown by Random::number when its $len argument is <= 0. The method promises a result in the range 0 <= result <= $len, which is impossible for a non-positive upper bound, so the guard rejects the input before calling random_int. It indicates a caller-side logic error (e.g. computing the bound from an empty count or negative size), not a failure of the secure random generator itself.","triggerScenarios":"Thrown at phalcon/Encryption/Security/Random.zep:274 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass len >= 1 (e.g. 16 for a 4-bit-random range)","Validate user-supplied lengths before calling number()"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","contentChangedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}