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

  1. Pass a string or number seed: random('my-seed').
  2. Pass null for non-deterministic: random(null).
  3. 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

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


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/a22724a85b34b739. Report an issue: GitHub.