Skip to content

Commit

Permalink
Math.random returns a number between 0 (inclusive) and 1 (exclusive)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Jun 8, 2022
1 parent 02099af commit 7660ae8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ while (i<256) HEX[i]=(256+i++).toString(16).substring(1);
export function hexoid(len) {
len||(len=16);
var str='',lh =((1+len)>>1)-1,num=lh;
while (num--) str += HEX[255*Math.random()|0];
while (num--) str += HEX[256*Math.random()|0];
return function () {
if (num === 255) {
str=''; num=lh;
while (num--) str += HEX[255*Math.random()|0];
while (num--) str += HEX[256*Math.random()|0];
}
return str + HEX[++num];
};
Expand Down
2 changes: 1 addition & 1 deletion src/unsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ while (i<256) HEX[i]=(256+i++).toString(16).substring(1);

export function hexoid(len){
len||(len=16);
var num=0,id=new Function('h','r','return '+new Array(((1+len)>>1)-1).fill('h[255*r.call()|0]').join('+')),str=id(HEX, r);
var num=0,id=new Function('h','r','return '+new Array(((1+len)>>1)-1).fill('h[256*r.call()|0]').join('+')),str=id(HEX, r);
return function(){
return (num === 255)
? (str=id(HEX, r))+HEX[num=0]
Expand Down

0 comments on commit 7660ae8

Please sign in to comment.