Code Monkey home page Code Monkey logo

prando's Issues

duplicated number in range

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.

ES6 import error

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

It is easy to bring generator into bad state by providing bad seed

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.

Outputs are not entirely random given seed

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 result is
Screenshot 2022-10-28 at 9 10 44 PM

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.