Skip to content

Instantly share code, notes, and snippets.

@nyawach
Last active November 13, 2019 10:28
Show Gist options
  • Save nyawach/ebd72286cbb5acd16fd2e1b9899b9d2b to your computer and use it in GitHub Desktop.
Save nyawach/ebd72286cbb5acd16fd2e1b9899b9d2b to your computer and use it in GitHub Desktop.
[0, n)の値をn個重複無しでランダム生成
// [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