MCPcopy Index your code
hub / github.com/mailvelope/mailvelope / getSecureRandom

Function getSecureRandom

src/modules/crypto.js:59–66  ·  view source on GitHub ↗
(from, to)

Source from the content-addressed store, hash-verified

57 * @return {Number} - a secure random number
58 */
59export function getSecureRandom(from, to) {
60 let randUint = getSecureRandomUint();
61 const bits = ((to - from)).toString(2).length;
62 while ((randUint & (Math.pow(2, bits) - 1)) > (to - from)) {
63 randUint = getSecureRandomUint();
64 }
65 return from + (Math.abs(randUint & (Math.pow(2, bits) - 1)));
66}
67
68function getSecureRandomUint() {
69 const buf = new Uint8Array(4);

Callers 2

crypto-test.jsFile · 0.90
initSecurityBgndFunction · 0.90

Calls 1

getSecureRandomUintFunction · 0.85

Tested by

no test coverage detected