Skip to content

proportionalJitter

Returns a number randomly jittered by a proportion of a base value

84 bytes
since v12.7.0

Usage

Add proportional noise to a base value by scaling a random offset with a given factor.

import * as
import _
_
from 'radashi'
const
const base: 100
base
= 100
import _
_
.
function proportionalJitter(base: number, factor: number): number

Returns a value randomly jittered by a proportion of the base value.

@seehttps://radashi.js.org/reference/random/proportionalJitter

@example

const result = proportionalJitter(100, 0.25)
result >= 75 && result <= 125
// => true

@version12.7.0

proportionalJitter
(
const base: 100
base
, 0.1) // => a number between 90 and 110

Basically, the example above is saying “add 10% noise to the base value”, in either direction (plus or minus).