• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var crypto = require('crypto')
3var MurmurHash3 = require('imurmurhash')
4
5module.exports = function (uniq) {
6  if (uniq) {
7    var hash = new MurmurHash3(uniq)
8    return ('00000000' + hash.result().toString(16)).substr(-8)
9  } else {
10    // Called without a callback, because this interface should neither block
11    // nor error (by contrast with randomBytes which will throw an exception
12    // without enough entropy).
13    //
14    // However, due to a change in Node 0.10.27+, pseudoRandomBytes is now the
15    // same as randomBytes, and may in fact block in situations where
16    // insufficent entropy is available.
17    return crypto.pseudoRandomBytes(4).toString('hex')
18  }
19}
20