uid-rn
v1.2.0
Published
a random number generator
Readme
--
generate-random-number
A simple and lightweight npm package for generating random integers within a specified range. Perfect for quick and efficient use in applications like games, simulations, or anywhere a random number is needed.
Installation
Using npm:
npm install uid-rnUsing yarn:
yarn add uid-rnUsage
Import the Function
You can import the package into your project as follows:
import uidRn from "uid-rn";Basic Example
Generate a random number using the default range (0 to 90):
const randomNumber = uidRn();
console.log(randomNumber); // Example output: 42Parameters
The uidRn function takes two optional parameters:
min(number):- The minimum value for the random number (inclusive).
- Default value:
0.
max(number):- The maximum value for the random number (exclusive).
- Default value:
90.
Examples
Default Usage
When no parameters are passed, the function generates a random number between 0 (inclusive) and 90 (exclusive):
uidRn(); // Example output: 67Custom Range
Specify a custom range by passing the min and max values:
// Random number between 10 and 50
const randomNumber = uidRn(10, 50);
console.log(randomNumber); // Example output: 23Negative Range
You can use negative numbers as the min or max value:
// Random number between -20 and 20
const randomNumber = uidRn(-20, 20);
console.log(randomNumber); // Example output: -5Large Ranges
Generate a random number within a larger range:
// Random number between 100 and 1000
const randomNumber = uidRn(100, 1000);
console.log(randomNumber); // Example output: 786Why Use This Package?
- Lightweight: No dependencies; focused on a single task.
- Flexible: Allows you to customize the range easily.
- TypeScript-Friendly: Includes built-in type definitions for seamless use in TypeScript projects.
- Beginner-Friendly: Intuitive and straightforward API.
Installation for Development
Clone the repository to make changes or enhance the package:
git clone https://github.com/yourusername/uid-rn.git
cd uid-rnInstall dependencies (if required):
npm installContributing
Contributions are welcome! If you’d like to improve the package, follow these steps:
- Fork the repository.
- Create a new branch with your feature or bug fix.
- Commit your changes.
- Open a pull request.
License
This package is licensed under the MIT License.
