[JAVA] Math.random() 정리 - 난수 생성하기

바위너구리·2022년 11월 18일
0
post-thumbnail

Math.random()

  • double 형
  • 0.0 이상 ~ 1.0 미만 사이의 값 반환

Math.random() * 10

  • double 형
  • 0.xxx ~ 9.xxx 사이의 값 반환

(int) Math.random() * 10

  • int 형
  • 0 ~ 9 사이의 값 반환

(int) Math.random() * 10 + 1

  • int 형
  • 1 ~ 10 사이의 값 반환

(int) Math.random() * 15 + 1

  • int 형
  • 1 ~ 15 사이의 값 반환

(int) Math.random() * 100 + 1

  • int 형
  • 1 ~ 100 사이의 값 반환

0개의 댓글