I am working on a Python Function that has to generate random strings of random lenght. The function has 3 parameters:
a=The minimum lenght that the generated string can have
b=The maximum lenght that the generated string can have
n=The number of strings that the program has to create
Here some examples:
random(2,6,3) --> 'asdf','rtgyh','as'
random(1,5,2) --> 'd', 'olkp'
random(2,9,4) --> 'ed','tgyhujik','edsrfb','esd'
This are the steps that i have to follow:
**generate a random number C between a and b
**generate a random string of lenght C
**add c to the list
(please try to be as basic as possible)
this is what i tired:
import random,string
def casualis(w,k,n):
l=[]
l2=[]
s=''
a='abcdefghijklmnopqrstuvwxyz'
while len(l)<(n+1):
for i in range (w,k+1):
l.append(random.randint(w,k))
for j in range(l[0]):
x=a[random.randint(1,25)]
s+=x
return l2
Aucun commentaire:
Enregistrer un commentaire