• 회원가입
  • 로그인
  • 구글아이디로 로그인

[module] Python - random.randrange() 메서드 ★★ - 지정 범위 안에서 정수형 난수 반환. (= randrange메서드 = 랜드레인지)

1865  

목차

  1. random.randrange() 예제 - 지정 범위 안 난수 생성
  2. random.randrange() 정의
  3. random.randrange() 구문
  4. random.randrange() 예제 - stop, step 매개변수

 

random.randrange() 예제 - 지정 범위 안 난수 생성

[예제] 3부터 7앞까지 1씩 증가하며 난수 생성.

※ 3, 4, 5, 6 중 하나.

 

import random

print(random.randrange(3, 7))

 

결과값 예: 5

 

random.randrange() 정의

 

지정 범위 안의 정수형 난수 반환.

 


cf.

random.uniform() : 지정 범위 안의 부동 소수형 난수 반환.

 

 

random.randrange() 구문

 

random.randrange(start, stop=None, step=1)

 


[매개변수]

 

start

선택. 시작값. (기본값: 0)

 

stop=None

필수. 종료값. (기본값: None) (포함 X)

 

step=1

선택. 증가폭. (기본값: 1)

 

 

random.randrange() 예제 - stop, step 매개변수

[예제] stop 매개변수만 있는 경우.


import random

print(random.randrange(4))

 

결과값: 0부터 4앞까지 1씩 증가하며 난수 생성. (0, 1, 2, 3 중 하나)


[예제2] start, stop, step 매개변수 다 있는 경우.


import random

print(random.randrange(1,4,2)) 

 

결과값: 1부터 4앞까지 2씩 증가하며 난수 생성. (1, 3 중 하나.)



분류 제목
module Python - random.vonmisesvariate() 메서드 △ - 폰미제스분포 (방향통계) 기반 랜…
module Python - random.paretovariate() 메서드 △ - 파레토분포 (확률이론) 기반 랜덤 부…
module Python - random.weibullvariate() 메서드 △ - 베이블분포 (통계) 기반 랜덤 부동…
module Python - requests 모듈 메서드 종류 (※ 요청 모듈)
module Python - requests.delete() 메서드 - 지정 URL에 DELETE 요청 보냄. (= de…
module Python - requests.get() 메서드 - 지정 URL에 GET 요청 보냄. (= get메서드 =…
module Python - requests.head() 메서드 - 지정 URL에 HEAD 요청 보냄. (= head메서…
module Python - requests.patch() 메서드 △ - 지정 URL에 PATCH 요청 보냄. (= pa…
module Python - requests.post() 메서드 -
module Python - requests.put() 메서드 △ - 지정 URL에 PUT 요청 보냄. (= put메서드…
module Python - requests.request() 메서드 △ - 지정 메서드의 요청을 지정 URL로 보냄. …
module Python - statistics 모듈 메서드 종류 (= 통계 모듈)
module Python - statistics.harmonic_mean() 메서드 - 조화 평균값 (= harmonic…
module Python - statistics.mean() 메서드 ★ - 평균값 (= mean메서드 = 민메서드)
module Python - statistics.median() 메서드 ★ - 중앙값 (= 중간값 = 가운데값 = med…
module Python - statistics.median_grouped() 메서드 -
module Python - statistics.median_high() 메서드 - 높은 중앙값 (= median_hig…
module Python - statistics.median_low() 메서드 - 낮은 중앙값 (= median_low메…
module Python - statistics.mode() 메서드 ★ - 최빈값 반환. (= mode메서드 = 모드)
module Python - statistics.pstdev() 메서드 -
2/7
목록
찾아주셔서 감사합니다. Since 2012