Skip to content

Instantly share code, notes, and snippets.

@nyawach
Created June 24, 2016 02:46
Show Gist options
  • Save nyawach/12a54672bd27917b4da327fa0f51cc25 to your computer and use it in GitHub Desktop.
Save nyawach/12a54672bd27917b4da327fa0f51cc25 to your computer and use it in GitHub Desktop.
[0, n)の数字からm個の値を抽出
function combination(n, m) {
var arr = [];
var num;
var i = 0;
while(i < m) {
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