[Javascript] 產生隨機亂數

uuid
https://github.com/kelektiv/node-uuid

唯一識別碼之UUID入門與實戰
https://juejin.im/post/5d5641d6f265da03c5030b46

nanoid
https://github.com/ai/nanoid

nanoid (non-secure for browser)
https://github.com/ai/nanoid/blob/master/non-secure/index.js

Crypto.getRandomValues (browser web api)
https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues

Crypto.randomBytes (node.js)
https://nodejs.org/api/crypto.html

Secure random values (in Node.js)
https://gist.github.com/joepie91/7105003c3b26e65efcea63f3db82dfba

CryptoJS Tutorial For Dummies (可使用CryptoJS.lib.WordArray.random)
https://www.davidebarranca.com/2012/10/crypto-js-tutorial-cryptography-for-dummies/


1.不要使用Math.random()
2.不要直接使用crypto.getRandomBytes,若真要使用需注意偏移量問題
3.NodeJS要產生隨機token,可使用uuid v4,此法也是基於randomBytes
4.瀏覽器Browser端可用CryptoJS產生亂數


#Javascript, uuid, guid, random, Crypto, CryptoJS, getRandomBytes, randomBytes, 亂數

留言