12345678910111213141516
  1. var createHash = require('create-hash');
  2. module.exports = function (seed, len) {
  3. var t = new Buffer('');
  4. var i = 0, c;
  5. while (t.length < len) {
  6. c = i2ops(i++);
  7. t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()]);
  8. }
  9. return t.slice(0, len);
  10. };
  11. function i2ops(c) {
  12. var out = new Buffer(4);
  13. out.writeUInt32BE(c,0);
  14. return out;
  15. }