---
title: "random: shader function examples, uses and input limits"
description: "A seeded hash produces a noise-like scalar from its input. Repeated seeds in a mathematical model give repeated outputs."
url: https://typeshade.dev/reference/functions/random/
language: en
---

# `random`

Function

A seeded hash produces a noise-like scalar from its input. Repeated seeds in a mathematical model give repeated outputs.

## Compare examples

The display shows the fractional part of a sine hash for different seeds. These are illustrative CPU calculations.

**Example 1`fract(sin(0 × 12.9898) × 43758.5453123)`**

**Result**

`0`

**Example 2`fract(sin(1 × 12.9898) × 43758.5453123)`**

**Result**

`0.9216954`

**Example 3`fract(sin(2 × 12.9898) × 43758.5453123)`**

**Result**

`0.05722738`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it for visual noise where cross-device equality is unnecessary.

## Inputs and limits

This compiler uses a sine hash whose GPU result varies by driver. The shown numbers are illustrative CPU calculations, not reproducible GPU random values or cryptographic randomness.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`fract`](https://typeshade.dev/reference/functions/fract/)
- [`sin`](https://typeshade.dev/reference/functions/sin/)

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Returns an `f32` in the range \[0, 1) hashed from an `f32`, `vec2` or `vec3` seed, emitted as `fract(sin(dot(seed, k)) * 43758.5453123)`.

## Syntax

```ts
declare function random(seed: f32 | vec2 | vec3): f32
```

## Parameters

- `seed` `f32 | vec2 | vec3`

## Return value

`f32`

## Description

One seed is one value in the IR and NOT on a GPU: WGSL bounds `sin` to 2^-11 absolute error on \[-PI, PI\] and not at all outside it, which is where this hash lives, so the driver decides the answer (surface section 55 has the measurements; #181 replaces the hash with an exact integer one). There is no unseeded form: `Math.random()` without a seed does not compile.

## Examples

- [`gallery/path-tracer/path-tracer.shade.ts`](https://typeshade.dev/guide/examples/path-tracer/)
- [`gallery/rt-renderer-class/rt-renderer-class.shade.ts`](https://typeshade.dev/guide/examples/rt-renderer-class/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [`Math.random`](https://typeshade.dev/reference/math/random/)
