Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

rand() is deterministic #5

TrevorBurnham opened this Issue Mar 20, 2011 · 2 comments


None yet
2 participants

Test case:

var bigint = require('bigint');

I don't know about you, but I get 116 every single time. The docs don't say anything about having to seed rand, and the examples don't appear to do so, either.

The gmp docs are a little ambiguous about this, but it looks like the line


should be followed by something like

gmp_randseed_ui(*randstate, seed);

where seed is an unsigned long. Easiest fix would be to use a system time function; the most robust solution (at least on Unix-derived systems) would be to read from /dev/random.


substack commented Mar 21, 2011

Just fixed in 0.2.2 and I added a test that should catch this seed issue in the future.

@substack substack closed this Mar 21, 2011

Thanks, that looks great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment