Is there a better way to create a randomizer web domain name generator?

Question:

i want to ask whether there is a better solution to get a much more randomize output. this is my code.

Combined = open("dictionaries/Combined.txt", 'r', encoding="utf-8")
Example = open("dictionaries/examples.txt", 'w', encoding="utf-8")

I first opened the dictionary and then the output is going to be written on a .txt file called example.txt. then i do this next.

for web_Test in Combined:
    Combined_result = re.search(r"([w-]+.)*w+[w-]*", web_Test)
    Text_Test = (Combined_result.group())
    Example.write((Text_Test+'.web'+'.co.id'+"n"))
    #print(Text+'.bni'+'.co.id')

My idea is that i used the Combined.txt file and create 5 different combination Example.write((Text_Test+'.web'+'.co.id'+"n")) from this code so that there would be much more text output variety.

This is what’s inside the combined text file

Combined.txt

After that i print out the output and this is what i got.

with open("dictionaries/examples.txt") as f:
    websamples = [line.rstrip() for line in f]
print (websamples)

['auth.web.co.id',
 'access.web.co.id',
 'account.web.co.id',
 'admin.web.co.id',
 'agree.web.co.id',
 'blue.web.co.id',
 'business.web.co.id',
 'cdn.web.co.id',
 'choose.web.co.id',
 'claim.web.co.id',
 'cl.web.co.id',
 'click.web.co.id',
 'confirm.web.co.id',
 'confirmation.web.co.id',
 'connect.web.co.id',
 'download.web.co.id',
 'enroll.web.co.id',
 'find.web.co.id',
 'group.web.co.id',
 'http.web.co.id',
 'https.web.co.id',
 'https-www.web.co.id',
 'install.web.co.id']

Now after I saw the output, I just realized that the output is not really random enough. It just straight up took the text from the combined text file one by one and just drop it there. even if i made a different combination of this line Example.write((Text_Test+'.web'+'.co.id'+"n")) it would be quite a waste of time. Is there a better way where I can do a randomized generated website domain?

For example I want the output that I got is install.web.co.id, but I want a more randomized output like web.install.co.id or install.web.install.co.id where it just took the words from the text and i add the web as the middle part and create a more website domain name variety.

Thx!

Asked By: Tsukuru

||

Answers:

you need the random.choice statement to select a random value from a list.
In my example you can also set the amount of results and subdomains.

BTW: You might reconsider using http and https as part of subdomains. That might be very confusing

my_list = ['access',
           'account',
           'admin',
           'agree',
           'blue',
           'business',
           'cdn',
           'choose',
           'claim',
           'cl',
           'click',
           'confirm',
           'confirmation',
           'connect',
           'download',
           'enroll',
           'find',
           'group',
           'http',
           'https',
           'https',
           'install'
           'web',
           ]

suffix = 'co.id'

output_count = 10
subdomain_count = 2
for i in range(output_count):
    out = []
    for j in range(subdomain_count):
        out.append(random.choice(my_list))
    out.append(suffix)
    print('.'.join(out))

output:

business.enroll.co.id
connect.confirmation.co.id
cdn.choose.co.id
http.cdn.co.id
choose.http.co.id
connect.cdn.co.id
group.admin.co.id
cdn.https.co.id
blue.click.co.id
group.cdn.co.id
Answered By: Ovski
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.