{"record":{"id":"a22724a85b34b739","repo":"remotion-dev/remotion","slug":"random-argument-must-be-a-number-or-a-string","errorCode":null,"errorMessage":"random() argument must be a number or a string","messagePattern":"random\\(\\) argument must be a number or a string","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/random.ts","lineNumber":45,"sourceCode":" */\nexport const random = (seed: RandomSeed, dummy?: unknown) => {\n\tif (dummy !== undefined) {\n\t\tthrow new TypeError('random() takes only one argument');\n\t}\n\n\tif (seed === null) {\n\t\treturn Math.random();\n\t}\n\n\tif (typeof seed === 'string') {\n\t\treturn mulberry32(hashCode(seed));\n\t}\n\n\tif (typeof seed === 'number') {\n\t\treturn mulberry32(seed * 10000000000);\n\t}\n\n\tthrow new Error('random() argument must be a number or a string');\n};\n","sourceCodeStart":27,"sourceCodeEnd":47,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/random.ts#L27-L47","documentation":"random() accepts seed of type number, string, or null (null yields Math.random()). After those branches, any other type (object, array, boolean, undefined) reaches the final throw because mulberry32 needs a numeric seed derived from a number or string hash.","triggerScenarios":"random({}), random(undefined), random(true), random([1,2]), or passing an object whose toString is not meaningful.","commonSituations":"Passing an object/config instead of a string key; default parameter missing; forgetting that null (not undefined) is the sentinel for non-deterministic mode.","solutions":["Pass a string or number seed: random('my-seed').","Pass null for non-deterministic: random(null).","Stringify objects: random(JSON.stringify(obj))."],"exampleFix":"// before\nconst v = random(props.config);\n// after\nconst v = random(JSON.stringify(props.config));","handlingStrategy":"validation","validationCode":"const seed = typeof obj === 'object' ? JSON.stringify(obj) : obj;\nconst v = random(seed as RandomSeed);","typeGuard":"const isRandomSeed = (v: unknown): v is number | string | null =>\n  v === null || typeof v === 'number' || typeof v === 'string';","tryCatchPattern":null,"preventionTips":["Pass a number or string seed.","Use null (not undefined) for non-deterministic random.","Stringify objects before using them as seeds."],"tags":["random","validation","types"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}