Created
June 24, 2016 02:46
-
-
Save nyawach/12a54672bd27917b4da327fa0f51cc25 to your computer and use it in GitHub Desktop.
[0, n)の数字からm個の値を抽出
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
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