import random
1. ๋ ์ธ์ ์ฌ์ด
print(random.randint(1, 10)) # 1 ~ 10
2. range ํจ์
print(random.randrange(10)) # 0 ~ 9
print(random.randrange(1, 10)) # 1 ~ 9
print(random.randrange(1, 10, 2)) # 1 ~ 9 ํ์๋ง, 1+2 ์ฆ๊ฐ
3. 0 ์ด์ 1 ๋ฏธ๋ง
print(random.random())
if random.random() < 0.5:
print('์๋
ํ์ธ์')
4. choice ํจ์ - ๋ฆฌ์คํธ์์ ๋๋ค
seasons = ['spring', 'summer', 'fall', 'winter']
print(random.choice(seasons))
5. shuffle() ํจ์ - ์์๋ก ์๋ ํจ์
my_list = [1, 2, 3, 4, 5]
random.shuffle(my_list)
print(my_list)
'๐์น ๊ฐ๋ฐ(Web) > ๐ํ์ด์ฌ(Python)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
datetime ๋ชจ๋ (0) | 2023.02.01 |
---|---|
ํ์ด์ฌ time ๋ชจ๋ (0) | 2023.02.01 |
ํ์ด์ฌ ํ์ค ๋ชจ๋ (0) | 2023.02.01 |
ํ์ด์ฌ ๋ชจ๋(module) (0) | 2023.02.01 |
ํ์ด์ฌ ํจ์(function) (0) | 2023.01.30 |