def zipf_rv(alpha, xmin=1, seed=None):
 if (xmin < 1):
  raise ValueError('xmin < 1')
 if (alpha <= 1):
  raise ValueError('a <= 1.0')
 if (not (seed is None)):
  random.seed(seed)
 a1 = (alpha - 1.0)
 b = (2 ** a1)
 while True:
  u = (1.0 - random.random())
  v = random.random()
  x = int((xmin * (u ** (- (1.0 / a1)))))
  t = ((1.0 + (1.0 / x)) ** a1)
  if ((((v * x) * (t - 1.0)) / (b - 1.0)) <= (t / b)):
   break
 return x

def zipf_rv ( alpha , xmin = 1 , seed = None ) : if ( xmin < 1 ) : raise ValueError ( 'xmin < 1' ) if ( alpha <= 1 ) : raise ValueError ( 'a <= 1.0' ) if ( not ( seed is None ) ) : random . seed ( seed ) a1 = ( alpha - 1.0 ) b = ( 2 ** a1 ) while True : u = ( 1.0 - random . random ( ) ) v = random . random ( ) x = int ( ( xmin * ( u ** ( - ( 1.0 / a1 ) ) ) ) ) t = ( ( 1.0 + ( 1.0 / x ) ) ** a1 ) if ( ( ( ( v * x ) * ( t - 1.0 ) ) / ( b - 1.0 ) ) <= ( t / b ) ) : break return x
return a random value chosen from the zipf distribution .