challenge n人中m人が当選するくじ

n人の中から公平にm人を選ぶ、くじ引きプログラムを作ってください。

Posted feedbacks - ActionScript

勉強し始めているので、とりあえず投稿
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
private function execute(n:int, m:int):void {
        var res:Array = [];
        for (var i:int = 0; i < m;) {
                var r:int = Math.floor(Math.random() * n);
                if (res.indexOf(r) >= 0) continue;
                i++;
                res.push(r);
        }
        Alert.show(res.toString());
}

Index

Feed

Other

Link

Pathtraq

loading...