def icd9_unique(self, current_age=0, gender=None, n=2): class icd9_iterator(): def __init__(self): self.i = 0 self.j = 0 self.n1 = 1000 self.n2 = 200 def __iter__(self): return self def __next__(self): if self.i < self.n1: if self.j < self.n2: res = str(self.i).zfill(3) + '.' + str(self.j) self.j += 1 return res else: self.j = 0 self.i += 1 if self.i == self.n1: raise StopIteration() return str(self.i).zfill(3) + '.' + str(self.j) else: raise StopIteration() return stats.reservoir_sampling(icd9_iterator(), n)
def random_int_unique(cls, min=0, max=9999, n=2): """ Generate n unique random integers uniformly distributed in the specified range. """ if (max - min + 1) < n: raise Exception('Not possible to generate {0} unique numbers in the range from {1} to {2}'.format( n, min, max)) if n < 2: return cls.random_int(min=min, max=max, variance=variance, mean=mean) return stats.reservoir_sampling(iter(range(min, max)), n)