Skip to content

Commit 6ab15f0

Browse files
author
Amit Kulkarni
committed
Use random instead of randint
1 parent 7b71a21 commit 6ab15f0

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

RandomNameGen/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## Random Username Generator
22

33
## Packages needed
4+
45
- requests
5-
- randint
6+
- random
67

78
You will need a url with list names in it, next you will have to access the name by the requests, fetch the names to the terminal
8-
Use the randint to randomly pick a name and display it
9+
Use the random to randomly pick a name and display it

RandomNameGen/user_generator.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
import requests
2-
from random import randint
2+
import random
33

44
url = 'https://svnweb.freebsd.org/csrg/share/dict/propernames?revision=61766&view=co'
55

6-
r = requests.get(url)
7-
text = r.text
8-
# print(text)
6+
names = requests.get(url).text
97

10-
# We are splitting the words to clear out the empty spaces
11-
individual_word = text.split()
12-
# print(individual_word)
8+
# We are splitting the words to clear out the empty spaces and create iterable
9+
individual_words = names.split()
1310

14-
# Next we need it to extract a random name we will use random library
15-
random_number = randint(0, len(individual_word))
16-
17-
# print(individual_word[random_number])
18-
19-
#to get random word with number
20-
print(individual_word[random_number] + str(random_number))
11+
# to get random word
12+
print(random.choice(individual_words))

0 commit comments

Comments
 (0)