Skip to content

Commit c2f695f

Browse files
authored
Merge pull request realpython#9 from uttamo/patch-1
Use random.choice instead of random.randint
2 parents 8eb0735 + 5b74528 commit c2f695f

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

scripts/13_random_name_generator.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from random import randint
1+
from random import choice
22

33

44
def random_name_generator(first, second, x):
@@ -10,13 +10,8 @@ def random_name_generator(first, second, x):
1010
- number of random names
1111
"""
1212
names = []
13-
for i in range(0, int(x)):
14-
random_first = randint(0, len(first)-1)
15-
random_last = randint(0, len(second)-1)
16-
names.append("{0} {1}".format(
17-
first[random_first],
18-
second[random_last])
19-
)
13+
for i in range(x):
14+
names.append("{0} {1}".format(choice(first), choice(second)))
2015
return set(names)
2116

2217

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy