Skip to content

Commit

Permalink
get rid of xkcd
Browse files Browse the repository at this point in the history
  • Loading branch information
brainwallet committed May 26, 2013
1 parent 63c0e18 commit fa41e1a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion js/brainwallet.js
Expand Up @@ -1092,7 +1092,11 @@
$('#compressed').click(update_gen_compressed);
gen_compressed = $('#compressed').hasClass('active');

$('#pass').val('correct horse battery staple');
var suggest = [];
for (var i=0; i < 6; i++)
suggest.push(mn_words[Math.floor(Math.random() * mn_words.length)]);
$('#pass').val(suggest.join(' '));

calc_hash();
generate();
$('#pass').focus();
Expand Down

5 comments on commit fa41e1a

@tlrobinson
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanielWeigl No, a random number between 0 and 1 multiplied by 2 and floored will result in 0 or 1.

But yeah, I'd be concerned about using Math.random() for cryptographic purposes.

@primalmotion
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tlrobinson, I browse Reddit, and I find you. You're everywhere dude.

@DanielWeigl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tlrobinson: "[...] Returns a floating-point, pseudo-random number in the range [0, 1) that is, from 0 (inclusive) up to but not including 1 (exclusive), which you can then scale to your desired range. [...]"
(from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random )

This means math.Random() will never return "1" -> so math.Random()*2 is strictly < 2. Therefor floor() will never return 2

@tlrobinson
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanielWeigl But JavaScript arrays are 0-indexed, so in a 2 element array there's no element at index 2...

@DanielWeigl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tlrobinson, ah - you a right, was my err... thx

Please sign in to comment.