{"record":{"id":"b5ae2213fe9d5b8c","repo":"remotion-dev/remotion","slug":"random-takes-only-one-argument","errorCode":null,"errorMessage":"random() takes only one argument","messagePattern":"random\\(\\) takes only one argument","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/random.ts","lineNumber":30,"sourceCode":"\n\tfor (i = 0; i < str.length; i++) {\n\t\tchr = str.charCodeAt(i);\n\t\thash = (hash << 5) - hash + chr;\n\t\thash |= 0; // Convert to 32bit integer\n\t}\n\n\treturn hash;\n}\n\nexport type RandomSeed = number | string | null;\n\n/*\n * @description A deterministic pseudo-random number generator. Pass in the same seed and get the same pseudorandom number.\n * @see [Documentation](https://www.remotion.dev/docs/random)\n */\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":12,"sourceCodeEnd":47,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/random.ts#L12-L47","documentation":"random(seed, dummy?) declares a second parameter only to detect old/mistaken calling conventions. If `dummy !== undefined` it throws immediately, catching callers who thought random() took a range (e.g. random(seed, max)). The function takes exactly one seed.","triggerScenarios":"Calling random(seed, 100), random(seed, min, max), or any form passing a second positional argument.","commonSituations":"Copy-pasting from a tutorial or library that used a different/older random API expecting a range argument.","solutions":["Remove the second argument: random(seed).","Scale the result yourself: random(seed) * (max - min) + min."],"exampleFix":"// before\nconst v = random(seed, 100);\n// after\nconst v = random(seed) * 100;","handlingStrategy":"type-guard","validationCode":"const v = random(seed); // never pass a second argument","typeGuard":"// TypeScript already enforces (seed, dummy?: unknown); for JS:\nconst callRandom = (seed: RandomSeed) => random(seed);","tryCatchPattern":null,"preventionTips":["Call random() with exactly one argument.","Scale ranges yourself: random(seed) * (max - min) + min.","Delete any second positional arg copied from old examples."],"tags":["random","api-misuse","validation"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}