Skip to content
Snippets Groups Projects
Commit c8bde318 authored by Aleksander Essex's avatar Aleksander Essex
Browse files

Fixed bias in voting booth random number generator

parent 8e023ee8
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ Random.getRandomInteger = function(max) { ...@@ -26,7 +26,7 @@ Random.getRandomInteger = function(max) {
var bit_length = max.bitLength(); var bit_length = max.bitLength();
Random.setupGenerator(); Random.setupGenerator();
var random; var random;
random = sjcl.random.randomWords(bit_length / 32, 0); random = sjcl.random.randomWords(Math.ceil(bit_length / 32)+2, 0);
// we get a bit array instead of a BigInteger in this case // we get a bit array instead of a BigInteger in this case
var rand_bi = new BigInt(sjcl.codec.hex.fromBits(random), 16); var rand_bi = new BigInt(sjcl.codec.hex.fromBits(random), 16);
return rand_bi.mod(max); return rand_bi.mod(max);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment