Function jitter

Jitters value by the absolute jitter amount. Returns a function.

All values should be on a 0..1 scale, and the return value is by default clamped to 0..1. Pass clamped:false as an option to allow for arbitary ranges.

jitter returns a function that calculates jitter. If you only need a one-off jitter, you can immediately execute the returned function:

import { jitter } from 'https://unpkg.com/ixfx/dist/modulation.js';
// Compute 10% jitter of input 0.5
const value = jitter({ relative: 0.1 })(0.5);

However, if the returned jitter function is to be used again, assign it to a variable:

import { jitter } from 'https://unpkg.com/ixfx/dist/modulation.js';
const myJitter = jitter({ absolute: 0.5 });

// Jitter an input value 1.0
const value = myJitter(1);

A custom source for random numbers can be provided. Eg, use a weighted random number generator:

import { weighted } from 'https://unpkg.com/ixfx/dist/random.js';
jitter({ relative: 0.1, source: weighted });

Options

  • clamped: If false, values out of percentage range can be used and return value may be beyond percentage range. True by default
  • random: Random source (default is Math.random)