[python] random 모듈

iberis2·2024년 4월 3일

python

목록 보기
4/6

python 에선 export 없이 다른 파일의 모듈을 가지고와 사용할 수 있다.

# my_module.py

pi = 3.141592
# main.py
import my_module

print(my_module.pi) # 3.141592

random

random.randint(시작할 숫자, 끝 숫자) : 시작할 숫자 부터 끝 숫자 사이의 무작위 정수를 반환한다.

  • 시작할 숫자, 끝 숫자 모두 포함된다.
      print(random.randint(0, 1)) # 0 또는 1 출력
    random.random() 0부터 1 사이의 무작위한 소수를 반환한다.
  • 0은 포함되고, 1은 포함되지 않는다
  • 0부터 5 사이의 무작위 소수를 찾고 싶다면?
    		random_float = random.random() * 5
FunctionSyntaxDescription
seedrandom.seed()Used to generate the same set of random numbers each time the algorithm is executed
randrangerandom.randrange(start,stop[,step])start, stop 사이에 step 간격의 무작위 실수 생성
randintrandom.randint(a,b)a, b 사이의 무작위 정수 생성
profile
자동화와 기록으로 더 효율적으로 일하는 으른 개발자가 되려고 합니다.

0개의 댓글