(no title)
sehrope | 8 years ago
If you want a random string get one directly via crypto.randomBytes(...)[2]:
const id = crypto.randomBytes(32).toString('hex');
[1]: https://github.com/bluzi/jsonstore/blob/87af0d3ef6bf11222b98...[2]: https://nodejs.org/api/crypto.html#crypto_crypto_randombytes...
cobookman|8 years ago
sehrope|8 years ago
If you're generating v4 UUIDs server side using the "uuid" NPM module then you're fine as internally it's using crypto.randomBytes(...)[1] with an almost 16-byte random string (UUIDs are 16-bytes but a proper v4 UUID has to override some of the bits to conform to the spec[2]).
If you're rolling your own UUID function or generating them client side then they may not be as random as you think. For example the same uuid NPM module silently uses Math.random()[3] on the client side if it can't find a better alternative. It's fine for something purely local to the one browser but I wouldn't rely on it being unique globally.
[1]: https://github.com/kelektiv/node-uuid/blob/17d443f7d8cfb65a7...
[2]: https://github.com/kelektiv/node-uuid/blob/17d443f7d8cfb65a7...
[3]: https://github.com/kelektiv/node-uuid/blob/17d443f7d8cfb65a7...
majewsky|8 years ago
bluzi|8 years ago