# yy-random

> a javascript random number API with seeded number support

Latest version **1.10.4** (published 2026-11-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install yy-random
pnpm add yy-random
yarn add yy-random
bun add yy-random
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.10.4 |
| Published | 2026-11-08 |
| First published | 2016-09-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 77.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | david figatner |
| Maintainers | davidfig |

## Links

- npm: https://www.npmjs.com/package/yy-random
- Repository: https://github.com/davidfig/random
- Homepage: https://github.com/davidfig/random#readme
- Issues: https://github.com/davidfig/random/issues
- npm.io page: https://npm.io/package/yy-random

## Dependencies (1)

- [seedrandom](https://npm.io/package/seedrandom.md) ^3.0.5

## Recent versions

- 1.10.4 (latest) — 2026-11-08
- 1.10.3 — 2026-11-07
- 1.10.2 — 2021-04-14
- 1.10.1 — 2020-12-04
- 1.10.0 — 2020-12-04
- 1.9.1 — 2020-10-19
- 1.9.0 — 2020-10-19
- 1.8.0 — 2019-04-22
- 1.7.3 — 2018-10-03
- 1.7.2 — 2018-06-27
- 1.7.1 — 2018-06-05
- 1.7.0 — 2018-06-05
- 1.6.0 — 2017-09-25
- 1.5.0 — 2017-07-29
- 1.3.0 — 2017-07-10
- … 9 more at https://npm.io/package/yy-random/versions

## README

## yy-random
yet another javascript random number API with seeded number support

## Code Example

    const Random = require('yy-random')

    // returns a random integer from 0 - 9
    Random.get(10)

    // returns a random float for 0 - 2
    Random.get(2, true)

    // changes the generator from Math.random() to a seeded random function
    Random.seed(100)

    // returns a random integer between 5 - 20 (including 5 and 20)
    // this will return the same number each time because of the Random.seed(100) call
    Random.range(5, 20) 

## Installation
include yy-random in your project or add to your workflow

    npm i yy-random

## Rationale
I use lots of random numbers in my game. I created this library to make it easier to generate the perfect number for as many scenarios as possible. The library has almost complete test code coverage.

## API
```js
    /**
     * generates a seeded number
     * @param {number} seed
     * @param {object} [options]
     * @param {string} [PRNG="alea"] - name of algorithm, see https://github.com/davidbau/seedrandom
     * @param {(boolean|string)} [state] - can include the state returned from save()
     */
    seed(seed, options) {

    /**
     * saves the state of the random generator
     * can only be used after Random.seed() is called with options.state = true
     * @returns {number} state
     */
    save() {

    /**
     * restores the state of the random generator
     * @param {number} state
     */
    restore(state) {

    /**
     * changes the generator to use the old Math.sin-based random function
     * based on : http://stackoverflow.com/questions/521295/javascript-random-seeds
     * (deprecated) Use only for compatibility purposes
     * @param {number} seed
     */
    seedOld(seed) {

    /**
     * create a separate random generator using the seed
     * @param {number} seed
     * @return {object}
     */
    separateSeed(seed) {

    /**
     * resets the random number this.generator to Math.random()
     */
    reset() {

    /**
     * returns a random number using the this.generator between [0, ceiling - 1]
     * @param {number} ceiling
     * @param {boolean} [useFloat=false]
     * @return {number}
     */
    get(ceiling, useFloat) {

    /**
     * returns a random integer between 0 - Number.MAX_SAFE_INTEGER
     * @return {number}
     */
    getHuge() {

    /**
     * random number [middle - range, middle + range]
     * @param {number} middle
     * @param {number} delta
     * @param {boolean} [useFloat=false]
     * @return {number}
     */
    middle(middle, delta, useFloat) {

    /**
     * random number [start, end]
     * @param {number} start
     * @param {number} end
     * @param {boolean} [useFloat=false] if true, then range is (start, end)--i.e., not inclusive to start and end
     * @return {number}
     */
    range(start, end, useFloat) {

    /**
     * an array of random numbers between [start, end]
     * @param {number} start
     * @param {number} end
     * @param {number} count
     * @param {boolean} [useFloat=false]
     * @return {number[]}
     */
    rangeMultiple(start, end, count, useFloat) {

    /**
     * an array of random numbers between [middle - range, middle + range]
     * @param {number} middle
     * @param {number} range
     * @param {number} count
     * @param {boolean} [useFloat=false]
     * @return {number[]}
     */
    middleMultiple(middle, range, count, useFloat) {

    /**
     * @param {number} [chance=0.5]
     * returns random sign (either +1 or -1)
     * @return {number}
     */
    sign(chance) {

    /**
     * tells you whether a random chance was achieved
     * @param {number} [percent=0.5]
     * @return {boolean}
     */
    chance(percent) {

    /**
     * returns a random angle in radians [0 - 2 * Math.PI)
     */
    angle() {

    /**
     * Shuffle array (either in place or copied)
     * from http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
     * @param {Array} array
     * @param {boolean} [copy=false] whether to shuffle in place (default) or return a new shuffled array
     * @return {Array} a shuffled array
     */
    shuffle(array, copy) {

    /**
     * picks a random element from an array
     * @param {Array} array
     * @return {*}
     */
    pick(array, remove) {

    /**
     * select a random collection of elements from an array
     * @param {Array} array
     * @param {number} count
     * @param {Array} array of selected items
     */
    select(array, count) {

    /**
     * returns a random property from an object
     * from http://stackoverflow.com/questions/2532218/pick-random-property-from-a-javascript-object
     * @param {object} obj
     * @return {*}
     */
    property(obj) {

    /**
     * creates a random set where each entry is a value between [min, max]
     * @param {number} min
     * @param {number} max
     * @param {number} amount of numbers in set
     * @param {number[]}
     */
    set(min, max, amount) {

    /**
     * returns a set of numbers with a randomly even distribution (i.e., no overlapping and filling the space)
     * @param {number} start position
     * @param {number} end position
     * @param {number} count of non-start/end points
     * @param {boolean} [includeStart=false] includes start point (count++)
     * @param {boolean} [includeEnd=false] includes end point (count++)
     * @param {boolean} [useFloat=false]
     * @param {number[]}
     */
    distribution(start, end, count, includeStart, includeEnd, useFloat) {

    /**
     * returns a random number based on weighted probability between [min, max]
     * from http://stackoverflow.com/questions/22656126/javascript-random-number-with-weighted-probability
     * @param {number} min value
     * @param {number} max value
     * @param {number} target for average value
     * @param {number} stddev - standard deviation
     */
    weightedProbabilityInt(min, max, target, stddev) {

    /**
     * returns a random number within a circle with a normal distribution
     * from https://stackoverflow.com/a/5838055/1955997
     * @param {number} x
     * @param {number} y
     * @param {number} radius
     * @param {bool} [float]
     * @returns {number[]} [x, y]
     */
    circle(x, y, radius, float) {

```
## License  
MIT License  
(c) 2017 [YOPEY YOPEY LLC](https://yopeyopey.com/) by [David Figatner](https://twitter.com/yopey_yopey/)

---
_Source: https://npm.io/package/yy-random · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
