SetTimeout random interval in javascript

by in on

Just few days back i got a request for my client to making a script that Increment Number with random interval. Then i thought to make a small plugin that generates random interval. How it works, is start number increments with a default value (1000) and set a cookie to user’s browser and every time this script update the cookies value so that when the user refresh there browser he/she get the same last incremented value. You can control the setTimeout random interval to change the value in the following line var rand = Math.round(Math.random() * (2000 - 200)) + 200;

Insert following Script:

Here is how you have to implemented this script on your website. Just insert the below javascript plugin into the .... tag or before the closed tag. No external javascript library is required for the plugin.


How to use Random Interval Script?

After inserted the above plugin, use the following code below the plugin inserted.


Here is the working fiddle you can find on