Socket
Socket
Sign inDemoInstall

@thi.ng/random

Package Overview
Dependencies
5
Maintainers
1
Versions
167
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @thi.ng/random

Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation


Version published
Weekly downloads
113K
increased by10.46%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@thi.ng/random

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 192 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation.

This package provides the IRandom interface and various (mostly seedable) pseudo-random number generator implementations, incl. IRandom wrappers for Math.random() and window.crypto:

Partially ported from C implementations taken from c.thi.ng.

Random distributions

Other utilities

Status

STABLE - used in production

Search or submit any issues for this package

Support packages

  • @thi.ng/ksuid - Configurable K-sortable unique IDs, ULIDs, binary & base-N encoded, 32/48/64bit time resolutions

Installation

yarn add @thi.ng/random

ESM import:

import * as rnd from "@thi.ng/random";

Browser ESM import:

<script type="module" src="https://cdn.skypack.dev/@thi.ng/random"></script>

Skypack documentation

For Node.js REPL:

const rnd = await import("@thi.ng/random");

Package sizes (brotli'd, pre-treeshake): ESM: 2.02 KB

Dependencies

Usage examples

Several projects in this repo's /examples directory are using this package:

ScreenshotDescriptionLive demoSource
Self-modifying, animated typographic grid with emergent complex patternsDemoSource
Probabilistic color theme generatorDemoSource
Interactive inverse FFT toy synthDemoSource
2D Bezier curve-guided particle systemDemoSource
Basic hiccup-based canvas drawingDemoSource
Barnsley fern IFS fractal rendererDemoSource
k-means clustering visualizationDemoSource
Randomized space-filling, nested grid layout generatorDemoSource
Randomized 4-point 2D color gradient image generatorDemoSource
Interactive pixel sorting tool using thi.ng/color & thi.ng/pixelDemoSource
Animated, iterative polygon subdivisions & visualizationDemoSource
Procedural stochastic text generation via custom DSL, parse grammar & AST transformationDemoSource
Generative audio synth offline renderer and WAV file exportDemoSource
Evolutionary shader generation using genetic programmingDemoSource
Responsive & reactively computed stacked column layoutDemoSource
Game of Life implemented as WebGL2 multi-pass shader pipelineDemoSource

API

Generated API docs

import { Smush32 } from "@thi.ng/random";

const rnd = new Smush32(0xdecafbad);

// the following methods are available for all generators

// next uint (0 .. 2^32-1)
rnd.int()
// 4022849029

// next float [0.0 .. 1.0)
rnd.float()
// 0.2698542904737066

// next normalized float (w/ opt scale)
// [-scale .. +scale)
rnd.norm(100)
// 57.70723665079737

// next float in given interval [min .. max)
rnd.minmax(10, 20)
// 15.295951807707537

rnd.minmaxInt(10, 20)

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-random,
  title = "@thi.ng/random",
  author = "Karsten Schmidt",
  note = "https://thi.ng/random",
  year = 2015
}

License

© 2015 - 2024 Karsten Schmidt // Apache License 2.0

Keywords

FAQs

Last updated on 11 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc