Math 객체

Math.ceil(arg)

Math.ceil(0.9); // 1
Math.ceil(215.02); // 216
Math.ceil(85.78); // 86

Math.round(arg)

Math.ceil(0.9); // 1
Math.ceil(215.02); // 215
Math.ceil(85.78); // 86

Math.floor(arg)

Math.ceil(0.9); // 0
Math.ceil(215.02); // 215
Math.ceil(85.78); // 85

Math.random(arg)

console.log(Math.random()); // 1~0 사이의 소수 반환

// 1 ~ 10 난수
let randomDouble = Math.random();
console.log(randomDouble, Math.ceil(randomDouble * 10)); // 0 < n <= 10 수 반환
console.log(randomDouble, Math.round(randomDouble * 10)); // 0 <= m <= 10 수 반환

// 0. 저장용 배열 만들기(length: 11, 각 요소의 값은 0)
const arrSaveCnt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
// 1. 루프 100만번 돌려
for(let i = 0; i < 1000000; i++) {
  //  1-1. 랜덤수 획득 'Math.ceil(Math.random() * 10)'
  const randomNum = Math.ceil(Math.random() * 10);

  //  1-2. 저장용 배열에 나온 숫자를 카운트해서 저장
  arrSaveCnt[randomNum]++;
};
// 2. 저장용 배열 확인
console.log(arrSaveCnt); // 랜덤으로 숫자가 생성된다.

abs.floor(arg)

Math.abs(1); // 1
Math.abs(0); // 0
Math.abs(-1); // 1