Python - Generate Random Numbers and Data Using the random Module
** Generate Random Numbers and Data Using the random Module
==========================================
import random
value = random.random()
print(value)
---------------------------------
0.9763078125267174
---------------------------------
0.7991571271641462
---------------------------------
0.05848808751761392
---------------------------------
...
---------------------------------
==========================================
import random
value = random.uniform(1, 10)
print(value)
---------------------------------
7.158342523317879
1.0916879633147998
7.9148940717269705
...
---------------------------------
==========================================
import random
value = random.randint(1, 6)
print(value)
---------------------------------
3
3
5
5
5
2
...
---------------------------------
==========================================
import random
value = random.randint(0, 1)
print(value)
---------------------------------
0
0
1
1
0
1
...
---------------------------------
==========================================
import random
greetings = ['Hello', 'Hi', 'Hey', 'Howdy', 'Hola']
value = random.choice(greetings)
print(value + ', LinuxerHAN!')
---------------------------------
Hey, LinuxerHAN!
Hola, LinuxerHAN!
Hello, LinuxerHAN!
...
---------------------------------
==========================================
import random
colors = ['Red', 'Black', 'Green']
results = random.choices(colors, k = 10)
print(results)
---------------------------------
['Green', 'Green', 'Red', 'Red', 'Black', 'Black', 'Black', 'Red', 'Green', 'Black']
---------------------------------
==========================================
import random
colors = ['Red', 'Black', 'Green']
results = random.choices(colors, weights=[18, 18, 2], k = 10)
print(results)
---------------------------------
['Green', 'Black', 'Black', 'Black', 'Red', 'Red', 'Black', 'Red', 'Black', 'Black']
['Black', 'Red', 'Red', 'Black', 'Black', 'Black', 'Black', 'Black', 'Red', 'Red']
['Black', 'Red', 'Black', 'Red', 'Red', 'Red', 'Black', 'Red', 'Black', 'Red']
...
---------------------------------
==========================================
import random
deck = list(range(1,53))
print(deck)
---------------------------------
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52]
---------------------------------
==========================================
import random
deck = list(range(1,53))
random.shuffle(deck)
print(deck)
---------------------------------
[19, 47, 4, 46, 22, 9, 2, 14, 8, 51, 39, 13, 36, 31, 40, 11, 45, 48, 16, 26, 43, 37, 15, 42, 52, 29, 10, 1, 24, 35, 32, 30, 38, 12, 41, 20, 18, 23, 17, 25, 28, 49, 34, 3, 5, 44, 50, 27, 33, 21, 6, 7]
---------------------------------
==========================================
import random
deck = list(range(1,53))
hand = random.sample(deck, k = 5)
print(hand)
---------------------------------
[8, 31, 28, 40, 35]
[41, 28, 40, 11, 4]
[13, 48, 44, 7, 15]
...
---------------------------------
==========================================
import random
first_names = ['김', '이', '박', '최', '한', '전', '양', '손', '신', '황']
last_names = ['영진', '미숙', '재인', '용석', '미자', '수연', '정수', '선미', '미현', '성규']
street_names = ['동성로', '홍대', '보문로', '명동', '자갈치', '한옥', '북한로', '펀치볼', '역전', '북문로']
fake_cities = ['메트로폴리스', '에리어', '킹스 랜딩', '써니달', '베드락', '사우스 팍', '아틀란티스']
states = ['서울', '경기도', '인천', '대구', '경상도', '전라도', '강원도', '울산', '부산', '충청도', '광주', '세종', '제주도']
for num in range(10):
first = random.choice(first_names)
last = random.choice(last_names)
phone = f'{random.randint(100, 999)}-5555-{random.randint(1000, 9999)}'
street_num = random.randint(100, 999)
street = random.choice(street_names)
city = random.choice(fake_cities)
state = random.choice(states)
zip_code = random.randint(10000, 99999)
address = f'{street_num} {street} St., {city} {state} {zip_code}'
email = first.lower() + last.lower() + '@linuxerhan.com'
print(f'{first} {last}\n{phone}\n{address}\n{email}\n')
---------------------------------
이 미숙
335-5555-3413
624 북문로 St., 베드락 대구 63399
이미숙@linuxerhan.com
신 영진
796-5555-9023
113 한옥 St., 베드락 전라도 92185
신영진@linuxerhan.com
최 미현
118-5555-7156
117 북문로 St., 써니달 대구 72062
최미현@linuxerhan.com
전 미자
364-5555-1847
161 북문로 St., 사우스 팍 강원도 33914
전미자@linuxerhan.com
김 미자
890-5555-7513
179 명동 St., 써니달 세종 84435
김미자@linuxerhan.com
황 선미
339-5555-2032
428 펀치볼 St., 킹스 랜딩 세종 69956
황선미@linuxerhan.com
전 수연
386-5555-1678
297 동성로 St., 써니달 강원도 84873
전수연@linuxerhan.com
최 수연
939-5555-7510
702 북한로 St., 킹스 랜딩 경상도 84370
최수연@linuxerhan.com
김 영진
528-5555-6917
676 홍대 St., 사우스 팍 서울 71470
김영진@linuxerhan.com
전 용석
854-5555-4103
296 명동 St., 베드락 대구 67091
전용석@linuxerhan.com
---------------------------------