{"id":"e621b23ecc9b6027","repo":"laravel/framework","slug":"the-seed-value-must-be-numeric","errorCode":null,"errorMessage":"The seed value must be numeric.","messagePattern":"The seed value must be numeric\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Grammars/MySqlGrammar.php","lineNumber":347,"sourceCode":"        return 'cast('.$value.' as json)';\n    }\n\n    /**\n     * Compile the random statement into SQL.\n     *\n     * @param  string|int  $seed\n     * @return string\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function compileRandom($seed)\n    {\n        if ($seed === '' || $seed === null) {\n            return 'RAND()';\n        }\n\n        if (! is_numeric($seed)) {\n            throw new InvalidArgumentException('The seed value must be numeric.');\n        }\n\n        return 'RAND('.(int) $seed.')';\n    }\n\n    /**\n     * Compile the lock into SQL.\n     *\n     * @param  \\Illuminate\\Database\\Query\\Builder  $query\n     * @param  bool|string  $value\n     * @return string\n     */\n    protected function compileLock(Builder $query, $value)\n    {\n        if (! is_string($value)) {\n            return $value ? 'for update' : 'lock in share mode';\n        }\n","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php#L329-L365","documentation":"MySqlGrammar::compileRandom() throws InvalidArgumentException when a seed is supplied that is not numeric. MySQL's RAND(n) only accepts a numeric seed; passing a string seed produces invalid SQL, so Laravel rejects it before compilation. An empty/null seed is allowed and produces RAND() with no argument.","triggerScenarios":"Calling inRandomOrder($seed) where $seed is a non-numeric, non-empty string (e.g. 'abc' or a UUID) on a MySQL/MariaDB connection. The error occurs when compileRandom builds the ORDER BY RAND(seed) SQL.","commonSituations":"Passing a request token or hash string as a random seed for reproducible shuffling. Reusing a string identifier from another engine's seed semantics on MySQL.","solutions":["Pass an integer seed (e.g. crc32 of the string) to RAND() for deterministic ordering.","Call inRandomOrder() with no argument for non-deterministic shuffling.","Sanitize the seed: cast with (int) or validate with is_numeric() before calling."],"exampleFix":"// before\n$query->inRandomOrder($request->input('seed'));\n\n// after\n$seed = $request->input('seed');\n$query->inRandomOrder(is_numeric($seed) ? (int) $seed : (empty($seed) ? '' : crc32($seed)));","handlingStrategy":"validation","validationCode":"$seed = $request->input('seed');\nif ($seed !== '' && $seed !== null && ! is_numeric($seed)) {\n    throw new \\InvalidArgumentException('inRandomOrder seed must be numeric on MySQL.');\n}\n$query->inRandomOrder($seed);","typeGuard":"function isValidMysqlSeed(mixed $seed): bool\n{\n    return $seed === '' || $seed === null || is_numeric($seed);\n}","tryCatchPattern":null,"preventionTips":["Cast string seeds to int (e.g. crc32) before passing to inRandomOrder on MySQL.","Validate seed input at the controller boundary.","Omit the seed argument entirely for non-deterministic ordering."],"tags":["random-order","mysql","validation","seed"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}