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

generate-numbers

v1.0.1

Published

A multi-threaded generator allowing to generate a large dataset of random numbers.

Downloads

2

Readme

number-generator

A multi-threaded generator allowing to generate a large dataset of random numbers.

Build Status CodeFactor DeepSource

Current version: 1.0.1

📋 Table of content

🚀 Install

npm install --global generate-numbers

Once installed, you can verify that the package was successfully installed by running the following command.

$ generate-numbers --version
v1.0.0

Using npx you can invoke generate-numbers without having to explicitely install the package.

$ npx generate-numbers --version
v1.0.0

🔰 Description

This command-line tool aims to provide an easy way to rapidly generate a large dataset of random numbers. It provides users with the ability to choose how many numbers to create and in which interval (min and max numbers), and will automatically partition the generation process across multiple worker threads depending on the CPU threads available.

I wrote this tool in order to be able to rapidly generate a set of random numbers in different formats (e.g textual, uint8, uint16, uint32 and uint64) to solve problems such as the Terasort design problem and to experiment using Worker Threads in NodeJS.

Note that this tool doesn't support parallelizing random number generation across multiple machines.

📘 Usage

Generating random numbers

The generate-numbers tool provides a convenient way to create random numbers. By default, the generated numbers are written to the standard output and can optionally be written to a file.

# The below example will create 10 million random numbers.
generate-numbers --amount 10000000

You will be prompted to validate the estimated size of the dataset to be generated, to avoid the prompt, you can use the --yes option.

Writing to a file

You can use generate-numbers to write the generated numbers to a file as well. Using this option will be much faster than using a shell redirection.

generate-numbers --amount 10000000 --output output.txt

Using different engines

Two random number generation engines are supported by this tool :

  • math-random which uses the Math.random() Javascript API to generate random numbers. Note that Math.random() is not a cryptographically-secure random number generator.
  • crypto-random which uses the Crypto API to generate cryptographically strong pseudorandom integers. Note that using the crypto-random engine will be much slower than using the math-random engine but will use more entropy to generate the numbers.

Using different formats

When generating pseudorandom numbers, you can choose different output formats depending on your needs. Below is a table describing the supported output formats along with their characteristics.

Format | Min | Max | Description ------ | --- | --- | ----------- text | −(2^53 − 1) | 2^53 − 1 | Displays numbers as comma-delimited ASCII numbers. u8 | 0 | 255 | Displays numbers as binary 8-bit integers. u16 | 0 | 65535 | Displays numbers as binary 16-bit integers. u32 | 0 | 4294967295 | Displays numbers as binary 32-bit integers. u64 | 0 | 2^53 − 1 | Displays numbers as binary 64-bit integers.

Parameters

  • -a, --amount <amount> - The amount of numbers to generate
  • -c, --chunk-size <size> - The size of the chunks to use when generating numbers (10000000 numbers by default)
  • -m, --min-number <min-number> - The minimum possible random number to generate (0, by default)
  • -x, --max-number <max-number> - The maximum possible random number to generate (1000, by default)
  • -t, --thread-count <count> - The number of worker threads to use (set to the number of available CPU by default)
  • -o, --output <file> - A path to a file to write the numbers to
  • -s, --stats-file <file> - A path to a file to write the statistics about the generated chunks to
  • -b, --backend <backend> - The generator backend to use (math-random or crypto-random)
  • -y, --yes - Automatically answer positively to confirmation prompts