본문 바로가기

Python

5.랜덤함수

from random import *

print(random())  #0.0 이상 1.0 미만의 임의의 값 무작위 생성
print(random() * 10) #0.0이상 10.0 미만의 임의의 값 생성 
print(int(random() * 10)) # 0이상 10 미만의 임의의 값 생성
print(int(random() * 10) + 1) #1이상 10이하의 임의의 값 생성

#로또 번호 뽑기
print(int(random() * 45) + 1) #1이상 45이하의 임의의 값 생성 
print(randrange(1,46)) #1이상 46미만의 임의의 값 생성 
print(randint(1,45))  #1이상 45이하의 임의의 값 생성
반응형

'Python' 카테고리의 다른 글

7.슬라이싱  (0) 2023.05.15
6.문자열  (0) 2023.05.15
4. 숫자 처리 함수  (0) 2023.05.15
3.간단 수식  (0) 2023.05.15
2.연산자  (0) 2023.05.15