randbytes
Version:
Get a buffer of random bytes from /dev/urandom file, time or another source
36 lines (26 loc) • 876 B
JavaScript
// Generated by CoffeeScript 1.4.0
(function() {
var TimeBasedRandomGenerator, instance;
instance = null;
TimeBasedRandomGenerator = (function() {
function TimeBasedRandomGenerator() {}
TimeBasedRandomGenerator.getInstance = function() {
if (!instance) {
instance = new TimeBasedRandomGenerator();
}
return instance;
};
TimeBasedRandomGenerator.prototype.getRandomBytes = function(bytes, callback) {
var byte, i, random, t, _i;
t = (new Date).getTime();
random = '';
for (i = _i = 1; _i <= bytes; i = _i += 1) {
byte = t * Math.floor((Math.random() * 1024) + 1) % 255;
random += String.fromCharCode(byte);
}
return callback(new Buffer(random, 'binary'));
};
return TimeBasedRandomGenerator;
})();
module.exports = TimeBasedRandomGenerator;
}).call(this);