Patch for an Issue #703

This commit is contained in:
Miroslav Stampar
2014-05-27 21:41:07 +02:00
parent 8b341e86fa
commit 680ab10ca6
2 changed files with 15 additions and 9 deletions

View File

@@ -917,7 +917,7 @@ def readInput(message, default=None, checkBatch=True):
return retVal
def randomRange(start=0, stop=1000):
def randomRange(start=0, stop=1000, seed=None):
"""
Returns random integer value in given range
@@ -926,9 +926,11 @@ def randomRange(start=0, stop=1000):
423
"""
return int(random.randint(start, stop))
randint = random.WichmannHill(seed).randint if seed is not None else random.randint
def randomInt(length=4):
return int(randint(start, stop))
def randomInt(length=4, seed=None):
"""
Returns random integer value with provided number of digits
@@ -937,9 +939,11 @@ def randomInt(length=4):
874254
"""
return int("".join(random.choice(string.digits if _ != 0 else string.digits.replace('0', '')) for _ in xrange(0, length)))
choice = random.WichmannHill(seed).choice if seed is not None else random.choice
def randomStr(length=4, lowercase=False, alphabet=None):
return int("".join(choice(string.digits if _ != 0 else string.digits.replace('0', '')) for _ in xrange(0, length)))
def randomStr(length=4, lowercase=False, alphabet=None, seed=None):
"""
Returns random string value with provided number of characters
@@ -948,12 +952,14 @@ def randomStr(length=4, lowercase=False, alphabet=None):
'RNvnAv'
"""
choice = random.WichmannHill(seed).choice if seed is not None else random.choice
if alphabet:
retVal = "".join(random.choice(alphabet) for _ in xrange(0, length))
retVal = "".join(choice(alphabet) for _ in xrange(0, length))
elif lowercase:
retVal = "".join(random.choice(string.ascii_lowercase) for _ in xrange(0, length))
retVal = "".join(choice(string.ascii_lowercase) for _ in xrange(0, length))
else:
retVal = "".join(random.choice(string.ascii_letters) for _ in xrange(0, length))
retVal = "".join(choice(string.ascii_letters) for _ in xrange(0, length))
return retVal