This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 랜덤함수 | |
from random import * | |
print(random()) # 0.0 이상 1.0 미만의 임의의 값 생성 | |
print(random() * 10) # 0.0 이상 10.0 미만의 임의의 값 생성 | |
print() | |
# 0 이상 10 미만의 임의의 값 생성 | |
print(int(random() * 10)) | |
print() | |
# 1 이상 10 이하의 임의의 값 생성 | |
print(int(random() * 10) + 1) | |
print() | |
# 1 이상 45 이하의 임의의 값 생성 | |
print(int(random() * 45) + 1) | |
print(int(random() * 45) + 1) | |
print(int(random() * 45) + 1) | |
print(int(random() * 45) + 1) | |
print(int(random() * 45) + 1) | |
print(int(random() * 45) + 1) | |
print() | |
# 1 이상 46 미만의 임의의 값 생성 | |
print(randrange(1, 46)) | |
print(randrange(1, 46)) | |
print(randrange(1, 46)) | |
print(randrange(1, 46)) | |
print(randrange(1, 46)) | |
print(randrange(1, 46)) | |
print() | |
# 1 이상 45 이하의 임의의 값 생성 | |
print(randint(1, 45)) | |
print(randint(1, 45)) | |
print(randint(1, 45)) | |
print(randint(1, 45)) | |
print(randint(1, 45)) | |
print(randint(1, 45)) |
[1] random() : 0.0 이상 1.0 미만의 임의의 값을 생성합니다.
[2] int(random()) : int로 랜덤 함수를 감싸게 되면 정수형으로 출력할 수 있습니다.
[3] randrange(A, B) : A 이상 B 미만의 임의의 값을 생성합니다.
[4] randint(A, B) : A 이상 B 이하의 임의의 값을 생성합니다.

'Python > Python Basic' 카테고리의 다른 글
파이썬 Basic : 문자열 처리 함수 (0) | 2020.03.08 |
---|---|
파이썬 Basic : 문자열과 슬라이싱 (0) | 2020.03.07 |
파이썬 Basic : 숫자 처리 함수 (0) | 2020.03.07 |
파이썬 Basic : 간단한 수식 (0) | 2020.03.07 |
파이썬 Basic : 연산자 (0) | 2020.03.07 |