persist-unique-random
v0.1.2
Published
Unique Random Array Generator with Persist(saving to file) Feature + Command Line Tool
Downloads
1
Maintainers
Readme
persist-unique-random - Unique Random Array Generator with Persist(saving to file) Feature + Command Line Tool
An Unique Random Array Generator with Persist(saving to file) Feature + Command Line Tool
PersistUniqueRandom=require('persist-unique-random');
rng=new PersistUniqueRandom({max:10});
for(var i=0;i<20;i++) console.log(rng.next());
//-> 7 5 6 2 3 8 9 1 4 0 7 5 6 ... (loop 7 5 6..)
rngShuffle=new PersistUniqueRandom({max:10,reshuffle:true});
for(var i=0;i<20;i++) console.log(rngShuffle.next());
//-> 7 5 6 2 3 8 9 1 4 0 8 2 1 ... (re-shuffle at loop point)
// * arrays are saved to $HOME/.persist-unique-random/persist-unique-random.json per 'id+min+max' pairs.
Module Reference
constructor(options)
- min: default=0
- max: default=16, range is 0-max-1 . i.e. default is 0-15 integer
- persist: set false if you dont wan't to save array file. default=true
- id: array id. this module keeps each seeds(random arrays) per 'id+min+max' pair. default='ID'
- fileDir: string of directory path of array file. default='$HOME/.persist-unique-random/'
- fileName: string of array file. default='persist-unique-random.json'
- reshuffle: set true is you want to re-shuffle random array at loop point. default=false
- forceSeed: number. force set random seed.
each seeds and index of unique random arrays are saved to a file to use next run of the process.
seed and index are saved per 'id+min+max' pair.
you can set persist:false to make this module as ordnary unique random array generator. index and arrays are not saved to file. this means random number will not be unique if you re-execute the process.
next()
returns random integer. index will be saved at this point.
reset()
reset current (id+min+max) random array.and save file.
resetAll()
reset all random array.and save file.
Install(CLI command line tool)
npm i -g persist-unique-random
Command line
unique-random [options]
Unique Random Array Generator with Persist(saving to file) Feature + Command Line Tool
Copyright (C) 2019-2019 @kssfilo(https://kanasys.com/gtech/)
Options
- h show this help
- ?
- d debug mode
- r reset specified random array.
- R reset all random arrays.
- i <id> random array id. random arrays are saved per id+min+max pair. default('ID')
- x <max> max value. e.g. 10 -> [0..9]. default:16
- n <min> min value. default:0
- s re-shuffle when random array loops. default:loops same array
- S <number> force override seed number. e.g. 12345. default:random number or saved seed.
- D <dir> directory to save random array seeds. default:$HOME/.persist-unique-random
- f <file> file name to save random array seeds. default:persist-unique-random
- N don't save/load random arrays.(generates non-unique random number)
Examples
Change Log
- 0.1.x: beta release