Skip to content

An adaptation of setInterval() that allows for random intervals within a given range.

Notifications You must be signed in to change notification settings

jabacchetta/set-random-interval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

setRandomInterval

setRandomInterval is an adaptation of JavaScript's native setInterval()function, allowing for both a minimum and maximum delay to be passed in, which is then used to invoke the callback at random intervals within the given range.

Purpose

There may be times where you'd like repetitive function calls to be executed on a more naturally-occurring timeline, as opposed to executing at fixed intervals. This is often the case when trying to emulate the real world in game development.

Installation

npm i set-random-interval

Usage

import setRandomInterval from 'set-random-interval';

// Pass in the callback, minimum delay (milliseconds), and maximum delay (milliseconds).
const interval = setRandomInterval(() => console.log('Hello World!'), 1000, 5000);

// Clear the interval if/when you'd like.
interval.clear();

About

An adaptation of setInterval() that allows for random intervals within a given range.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published