2018-09-22 16:12:20 +00:00
|
|
|
function generateRandom(template) {
|
|
|
|
return template.replace(/[xy]/g, function(c) {
|
2018-12-20 23:52:26 +00:00
|
|
|
var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
|
2014-05-23 18:14:06 +00:00
|
|
|
return v.toString(16);
|
2018-09-22 16:12:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function guid() {
|
|
|
|
return generateRandom('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx').toUpperCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a string of n random characters. Defaults to n=6.
|
|
|
|
*/
|
|
|
|
function randomChars(n) {
|
|
|
|
n = n || 6;
|
|
|
|
var template = 'x'.repeat(n);
|
|
|
|
return generateRandom(template);
|
2014-05-23 18:14:06 +00:00
|
|
|
}
|
2013-05-31 01:38:44 +00:00
|
|
|
|
2014-05-23 18:14:06 +00:00
|
|
|
function nop() {}
|
2013-05-31 01:38:44 +00:00
|
|
|
|
2014-05-23 18:14:06 +00:00
|
|
|
module.exports = {
|
|
|
|
guid: guid,
|
2018-09-22 16:12:20 +00:00
|
|
|
nop: nop,
|
|
|
|
randomChars: randomChars
|
2014-05-23 18:14:06 +00:00
|
|
|
};
|