function shuffle(arr) {
arr.sort(() => Math.random() - 0.5);
}
function shuffle(array) {
array.sort(() => Math.random() - 0.5);
}
개 엠창 걸레년 딱대 ㅋㅋㅋ
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
// 1, 2, 3으로 만들 수 있는 모든 순열의 빈도를 세줍니다.
let count = {
'123': 0,
'132': 0,
'213': 0,
'231': 0,
'321': 0,
'312': 0
};
for (let i = 0; i < 1000000; i++) {
let array = [1, 2, 3];
shuffle(array);
count[array.join('')]++;
}
// 만들 수 있는 모든 순열의 생성 빈도를 세서 출력해줍니다.
for (let key in count) {
alert(`${key}: ${count[key]}`);
}
자살하러감
댓글 0