Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pcg

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pcg

A functional typescript implementation of the PCG family random number generators

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
102K
increased by10.08%
Maintainers
2
Weekly downloads
 
Created
Source

pcg

Version Tests Coverage Downloads License

A functional implementation of the PCG family random number generators, written in JavaScript.

Getting started

To achieve frictionless reproducibility of random output results, immutable objects are used throughout the project.

First, seed a PCG state. A stream ID specifies which unique periodic series of entropy to use. The state specifies where in that series we start.

import { createPcg32 } from 'pcg'

const advancedOptions = {}
const initState = 42
const initStreamId = 54
const state0 = createPcg32(advancedOptions, initState, initStreamId)

After that, random outputs can be generated by calling appropriate functions as shown below:

import { nextState, prevState, randomInt, randomList } from 'fn-pcg'

const randomUint32 = randomInt(0, 2 ** 32 - 1)
const [value, nextState] = randomUint32(state0)

const listLength = 3
const listItemRng = randomUint32
const [[v1, state1], [v2, state2], [v3, state3]] = randomList(listLength, listItemRng, state0)

In this above example, value === v1, and nextState === state1

Thanks

  • @kripod, who wrote the original pcg.js

FAQs

Package last updated on 10 May 2023

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