def random_combination_with_replacement(iterable, r):
 pool = tuple(iterable)
 n = len(pool)
 indices = sorted((random.randrange(n) for i in xrange(r)))
 return tuple((pool[i] for i in indices))

def random_combination_with_replacement ( iterable , r ) : pool = tuple ( iterable ) n = len ( pool ) indices = sorted ( ( random . randrange ( n ) for i in xrange ( r ) ) ) return tuple ( ( pool [ i ] for i in indices ) )
random_combination -> tuple arguments: iterable: an iterable .