Skip to content

Commit 263c23a

Browse files
Merge pull request #128 from pnappa/pnappa-fix-random-bias
2 parents 09c28ab + f100a81 commit 263c23a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

source/ulid.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ export function detectPRNG(root?: any): PRNG {
5252
return () => {
5353
const buffer = new Uint8Array(1);
5454
globalCrypto.getRandomValues(buffer);
55-
return buffer[0] / 0xff;
55+
return buffer[0] / 256;
5656
};
5757
} else if (typeof globalCrypto?.randomBytes === "function") {
58-
return () => globalCrypto.randomBytes(1).readUInt8() / 0xff;
58+
return () => globalCrypto.randomBytes(1).readUInt8() / 256;
5959
} else if (crypto?.randomBytes) {
60-
return () => crypto.randomBytes(1).readUInt8() / 0xff;
60+
return () => crypto.randomBytes(1).readUInt8() / 256;
6161
}
6262
throw new ULIDError(ULIDErrorCode.PRNGDetectFailure, "Failed to find a reliable PRNG");
6363
}

0 commit comments

Comments
 (0)