I made a program to random generate a pronounceable 4 word.
the code is,
import random
vowels = ['a','e','i','o','u']
consonants = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z']
a = random.sample(consonants,2)
a.insert(1,random.choice(vowels))
a.append(random.choice(vowels))
print "".join(a)
snap - explanation : taking vowels and consonants in two lists - use random.sample to fetch two consonants as list - then insert and append vowels - then make list to string and print it.
o/p:
[parthi@localhost pyth files]$ python randgen.py
culo
[parthi@localhost pyth files]$ python randgen.py
xuki
[parthi@localhost pyth files]$ python randgen.py
tuju
[parthi@localhost pyth files]$ python randgen.py
ziqu
No comments:
Post a Comment