Random Number JS
Generate random numbers with more variety
This function also runs fast, and uses the time in milliseconds to help add variety to its random results. The function, also (optionally, true by default) keeps track of recent random results, and tries to avoid repeating them, but does so randomly. The functions memory for recent random numbers is also cleared on a 1 second interval by default, and can be changed (or disabled) with a function as shown below.
- added option to avoid repeat numbers within a radius of each other
- enabling lite mode globally now disables the clear interval automatically
npm install @aspiesoft/random-number-js
// require only if using node.jsconst random = require('@aspiesoft/random-number-js');random(); // output: (25) random number between 0 and 100random(10, 50); // output: (42) random number between 10 and 50random(-50, 50, 2); // output: (23.02, -45.53, 2.5) random number between -50 and 50random(0, 100, -1); // output: random number with a random decimal size between 0 and 10random(0, 1, 10); // output: random number with a random decimal size between 0 and e^10// reduce the chance of numbers being near each otherrandom.setAvoidRadius(10); // default: 0// will treat numbers within a distance of 10 of any previous number, as if it's a repeated number// example: if output1 = 5 and output2 = 7, because 7-10 <= 5, output2 counts as a repeat of output1// optional enable lite mode (false by default)// changes the default option, and can be (optionally) overwritten by the functionrandom.setLiteMode(true || false); // default: true (default for function attr, Not for the option)// be default, the random function remembers past results for 1 second, and avoids repeating them.// setting lite mode disables this feature, and reduces memory usage.// the numbers will still often have variety, but with a higher chance of repeats// change the interval for clearing previous resultsresult.setClearInterval(1000); // default: 1000 (1000 milliseconds = 1 second)result.setClearInterval(0); // disable intervalrandom("<insert minimum value>", // default: 0"<insert maximum value>", // default: 100"<insert decimal size>", // default: 0// individually set lite mode for current function (only works if lite mode is globally disabled)true || false, // default: null (uses default option));