たとえば UUID v4 の生成で次のようなコードを書いた場合、得られる UUID の周期はどうなるのでしょうか ?
js
1// refer: https://github.com/googlearchive/chrome-platform-analytics/blob/master/src/internal/identifier.js#L44 2const UUID_FORMAT = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' 3const generateRandomInt = n => Math.floor(Math.random() * n) 4const generateUuidV4 = () => ( 5 UUID_FORMAT.split('').map(c => { 6 switch(c) { 7 case 'x': 8 return generateRandomInt(16).toString(16) 9 case 'y': 10 return (generateRandomInt(4) + 8).toString(16) 11 default: 12 return c 13 } 14 }).join('') 15)
Math.random
が十分な乱数周期と一様さを持っている場合、 4bit の x
の個数 30 個と 2bit の y
の個数 1 個で (2 ^ 4) ^ 30 * (2 ^ 2) = 2 ^ 122 の周期を持つ、と考えてよいのでしょうか ?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/02 07:53
2018/01/02 07:54
2018/01/05 08:26