maybe this is a rookie question, but how can i get a new random number everytime it repeats?
realport = random.randint(portstarts, portends)
liste = list(itertools.repeat('{}:{}:{}:{}'.format(hostname, realport, username, password), amount))
maybe this is a rookie question, but how can i get a new random number everytime it repeats?
realport = random.randint(portstarts, portends)
liste = list(itertools.repeat('{}:{}:{}:{}'.format(hostname, realport, username, password), amount))
as ShadowRanger commented, itertools.repeat
probably isn't what you want.
A "list comprehension" might be a nicer way of expressing what you want:
def getport():
return random.randint(portstarts, portends)
liste = [
'{}:{}:{}:{}'.format(hostname, getport(), username, password)
for _ in range(amount)
]
if you want all of the ports to be unique, then you could instead use random.sample
to "sample without replacement":
liste = [
'{}:{}:{}:{}'.format(hostname, port, username, password)
for port in random.sample(range(portstarts, portends+1), amount)
]
see, e.g. How to incrementally sample without replacement? for various ways to sample without replacement in Python