Last active
November 13, 2019 10:28
-
-
Save nyawach/ebd72286cbb5acd16fd2e1b9899b9d2b to your computer and use it in GitHub Desktop.
[0, n)の値をn個重複無しでランダム生成
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [0, n)の値をn個ランダムで生成した配列を返す | |
function makeRandomNumberArr(n) { | |
let arr = []; | |
let i = 0; | |
let num; | |
while(i < n) { | |
num = Math.floor(Math.random() * n); | |
if(~arr.indexOf(num)) continue; | |
arr.push(num); | |
i++; | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment