npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

recoverable-random

v1.0.5

Published

A recoverable number generator that generates pseudorandom integer or floating-point numbers within a given range.

Downloads

314

Readme

recoverable-random

Tests MIT License   Donation

npm version npm downloads

A recoverable number generator that generates pseudorandom integer or floating-point numbers within a given range.

🗝️ Features

  • Recoverable
  • Supports float and integer
  • Supports seed
  • Supports TypeScript
  • Zero dependencies

🚀 Getting Started

Installation

npm install recoverable-random

Visit the npm page.

Import

// ES6
import NumberGenerator from "recoverable-random";

// CommonJS
const NumberGenerator = require("recoverable-random").default;

Usage Example~ 🍀

// import the module
import NumberGenerator from "recoverable-random";
// or
const NumberGenerator = require("recoverable-random").default;

// create a generator instance
const generator = new NumberGenerator("seed");

// generate a random integer between 0 and 9
console.log(generator.random(0, 10));
// >>> 6

// generate a random floating-point number between 0 and 9
console.log(generator.random(0, 10, true));
// >>> 1.458055829850764 

// get the state code of the generator
const stateCode = generator.getStateCode();

console.log(generator.random(0, 10));
// >>> 6
console.log(generator.random(0, 10));
// >>> 8

// recover the state of the generator
generator.recoverState(stateCode);

console.log(generator.random(0, 10));
// >>> 6
console.log(generator.random(0, 10));
// >>> 8

📖 API Reference

Constructor

Creates a new instance of the NumberGenerator class.

new NumberGenerator(seed?: number | string)

| Parameter | Optional | Type | Default | Description | |-|-|-|-|-| | seed | Yes | number | string | undefined | The seed value of the generator. |

Static Methods

Converts a string to seed.

NumberGenerator.stringToSeed(str: string)

| Parameter | Optional | Type | Default | Description | |-|-|-|-|-| | str | No | string | - | The string to be converted. |

| Return Type | Description | |-|-| | number | The seed value. |

Methods

Generates a pseudorandom number within the specified range.

random(min: number, max: number, isFloat?: boolean)

| Parameter | Optional | Type | Default | Description | |-|-|-|-|-| | min | No | number | - | The minimum value of the range. | | max | No | number | - | The maximum value of the range. | | isFloat | Yes | boolean | false | Whether the generated number is a floating-point number. |

| Return Type | Description | |-|-| | number | The generated number. |

Gets the state code of the generator.

getStateCode()

| Return Type | Description | |-|-| | string | The state code of the generator. |

Recovers the state of the generator.

recoverState(stateCode: string)

| Parameter | Optional | Type | Default | Description | |-|-|-|-|-| | stateCode | No | string | - | The state code of the generator. |

Sets the seed of the generator.

setSeed(seed: number | string)

| Parameter | Optional | Type | Default | Description | |-|-|-|-|-| | seed | No | number | string | - | The seed value of the generator. |

🤝 Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue. If you want to contribute code, please fork the repository and submit a pull request.

Before you open a pull request, please make sure that you run npm run dev:test to make sure the code run as expected.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details

☕ Donation

Love the program? Consider a donation to support my work.

"Donation" <- click me~