Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// ### function randomString (length) | ||
// #### @length {integer} The number of bits for the random base64 string returned to contain | ||
// randomString returns a pseude-random ASCII string (subset) | ||
// the return value is a string of length ⌈bits/6⌉ of characters | ||
// from the base64 alphabet. | ||
// | ||
function randomString(length) { | ||
let rand, i, ret, bits; | ||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'; | ||
const mod = 4; | ||
|
||
ret = ''; | ||
// standard 4 | ||
// default is 16 | ||
bits = length * mod || 64; | ||
|
||
// in v8, Math.random() yields 32 pseudo-random bits (in spidermonkey it gives 53) | ||
while (bits > 0) { | ||
// 32-bit integer | ||
rand = Math.floor(Math.random() * 0x100000000); | ||
//we use the top bits | ||
for (i = 26; i > 0 && bits > 0; i -= mod, bits -= mod) { | ||
ret += chars[0x3f & (rand >>> i)]; | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
module.exports = { | ||
randomString, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters