Skip to content

kdby-io/range-shuffle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Range-Shuffle Build Status Version Download Greenkeeper badge

Wide-range integer shuffler.

Goals

  • No array
  • Reversible

Getting Started

Install

npm install --save range-shuffle

Usage

const Shuffler = require('range-shuffle');
// or
import Shuffler from 'range-shuffle';

const rs = new Shuffler({
  MULTIPLIER: 7, // it must be a prime number
  INCREMENT: 9,
  MODULUS: 10,
});

const array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const shuffled = array.map(int => rs.LCG(int));
// [9, 6, 3, 0, 7, 4, 1, 8, 5, 2]
const reversed = shuffled.map(int => rs.reverseLCG(int));
// [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Principle

Linear congruential generator

Note

All constants & method arguments can be both Number and String type.
If you want to use a large number over Number.MAX_SAFE_INTEGER(9007199254740991), use a String type input like .LCG('9999999999999999').

API

new Shuffler(constants)

constants is a object that must contain three constants:

  • MULTIPLIER: Must be a prime number.
  • INCREMENT
  • MODULUS: Range for shuffling. 0 ~ (MODULUS - 1)

.LCG(integer)

Performs linear congruential generating based on constants.

.reverseLCG(integer)

Restores linear congruential generating based on constants.

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •