remotion-dev/remotion · error · Error
random() argument must be a number or a string
Error message
random() argument must be a number or a string
What it means
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.
Source
Thrown at packages/core/src/random.ts:45
*/
export const random = (seed: RandomSeed, dummy?: unknown) => {
if (dummy !== undefined) {
throw new TypeError('random() takes only one argument');
}
if (seed === null) {
return Math.random();
}
if (typeof seed === 'string') {
return mulberry32(hashCode(seed));
}
if (typeof seed === 'number') {
return mulberry32(seed * 10000000000);
}
throw new Error('random() argument must be a number or a string');
};
View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Pass a string or number seed: random('my-seed').
- Pass null for non-deterministic: random(null).
- Stringify objects: random(JSON.stringify(obj)).
Example fix
// before const v = random(props.config); // after const v = random(JSON.stringify(props.config));
Defensive patterns
Strategy: validation
Validate before calling
const seed = typeof obj === 'object' ? JSON.stringify(obj) : obj; const v = random(seed as RandomSeed);
Type guard
const isRandomSeed = (v: unknown): v is number | string | null => v === null || typeof v === 'number' || typeof v === 'string';
Prevention
- Pass a number or string seed.
- Use null (not undefined) for non-deterministic random.
- Stringify objects before using them as seeds.
When it happens
Trigger: random({}), random(undefined), random(true), random([1,2]), or passing an object whose toString is not meaningful.
Common situations: Passing an object/config instead of a string key; default parameter missing; forgetting that null (not undefined) is the sentinel for non-deterministic mode.
Related errors
- HtmlInCanvas: `width` and `height` must be numbers. Received
- You passed to durationInFrames an argument of type ${typeof
- You passed to the "from" props of your <Sequence> an argumen
- Value must be a string, but is ${JSON.stringify(value)}
- random() takes only one argument
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/a22724a85b34b739.
Report an issue: GitHub.