Skip to content

jmacmahon/reproducible-random

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reproducible-random

Thin wrapper around random-js (https://github.com/ckknight/random-js) to provide reproducibility.

The intended use-case is within test suites which generate random data for fuzzing -- using this library will allow you to run the exact same test suite with the same fuzzed data, which should help with debugging flickering tests.

Usage

In Typescript/ES6:

import { random } from 'reproducible-random'

const foo = random.integer(0, 100)
const bar = random.bool()
console.log({
    foo,
    bar,
})

When run, this will output a line of the form RANDOM_SEED=123456789 on the console, which can then be passed back in as an environment variable for reproducing the same random data.

> tsc file.ts
> node file.js
RANDOM_SEED=2892099504791794
{ foo: 41, bar: false }
> RANDOM_SEED=2892099504791794 node file.js
RANDOM_SEED=2892099504791794
{ foo: 41, bar: false }

About

Wrapper around random-js for reproducibility

Resources

Stars

Watchers

Forks

Packages

No packages published