zeh / prando Goto Github PK
View Code? Open in Web Editor NEWDeterministic pseudo-random number generator for JavaScript and TypeScript
License: MIT License
Deterministic pseudo-random number generator for JavaScript and TypeScript
License: MIT License
hey, very useful project. but i found a problem with duplicated number in range.
example:
const random = new Prando('duoreading is nice :)')
for (let i = 0; i <= 1513; i++) {
console.log(random.nextInt(100000, 999999))
}
681267 is duplicated.
also i generated userId this way and i lost a lot of users haha. going to add a check for duplicated id now.
A TS file such as:
import Prando from 'prando';
const test = new Prando();
Compiled to JS and ran throws:
const test = new prando_1.default();
^
TypeError: prando_1.default is not a constructor
at Object.<anonymous> (/.../dist/prando.test.js:5:14)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
Doing the require
method allows construction of a Prando
object but breaks all the typing.
Same result in Node versions 8.9.2
and 10.12.0
When using Prando in tests as a source of reproducible randomness, it is tempting to initialize it with some simple seeds such as '', '42' or '43'.
I'm noticing a number of problems when doing so.
First, when the seed is empty string, Prando seems to get into some stuck state and keeps returning the same number (0.5000000001164153) again and again.
Repro:
it('not eq', () => {
const p = new Prando('');
expect(p.next()).not.toEqual(p.next());
});
Second, when using two different seed strings '42', and '43', one could expect the two generated sequences to be completely different (avalanche effect), however they look quite similar (at least first produced number).
I understand that Prando is not designed to provide cryptographical level of randomness, but I expected it to provide at least "random enough" numbers to do basic statistics.
I guess what I expected could be done by calling some cryptographic hash function on the seed before passing it into Prando, buy I'm curious why Prando would not do this internally already.
Following up on #1. I know the issue is marked as resolved, but it seems like the output is still not truly random given incrementing integer seeds.
For example, I am instantiating multiple Prando instances, and using "between" to pick random points on a map (each pick is using a unique Prando instance). The seed is incrementing integers (1, 2, 3...) for each subsequent instance.
The points circled are the result of adjacent integers. As you can see, there's clearly a non-random pattern when seeds are adjacent integers.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.