New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@js-util/random-int

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@js-util/random-int

Returns a random value between max (exclusive) and min (inclusive)

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

Random Int

Returns a random int between the max (exclusive) and min (inclusive) bounds

npm install

npm install --save @js-util/random-int

Example usage

// Importing the module
const randomInt = require("@js-util/random-int");

// Get some random value
let value = randomInt(0, 100);

Its code

/**
 * Returns a random int between the min, and max bound
 * 
 * @param {int} min value to generate, inclusively (meaning its possible to return min)
 * @param {int} max value to generate, exclusively (meaning it never returns max, unless max == min)
 * 
 * @return {int} random int between max (exclusive) and min (inclusive)
 */
function randomInt(min, max) {
	min = Math.ceil(min);
	max = Math.floor(max);
	return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}

// Export the function
module.exports = randomInt;

Keywords

FAQs

Package last updated on 24 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc