Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b74528

Browse files
authored
Use random.choice instead of random.randint
random.choice is better for selecting random elements from a list than using random.randint to generate random indices to select
1 parent8eb0735 commit5b74528

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-
fromrandomimportrandint
1+
fromrandomimportchoice
22

33

44
defrandom_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-
foriinrange(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+
foriinrange(x):
14+
names.append("{0} {1}".format(choice(first),choice(second)))
2015
returnset(names)
2116

2217

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp