def random_threshold_sequence(n, p, seed=None):
 if (not (seed is None)):
  random.seed(seed)
 if (not (0 <= p <= 1)):
  raise ValueError('p must be in [0,1]')
 cs = ['d']
 for i in range(1, n):
  if (random.random() < p):
   cs.append('d')
  else:
   cs.append('i')
 return cs

def random_threshold_sequence ( n , p , seed = None ) : if ( not ( seed is None ) ) : random . seed ( seed ) if ( not ( 0 <= p <= 1 ) ) : raise ValueError ( 'p must be in [0,1]' ) cs = [ 'd' ] for i in range ( 1 , n ) : if ( random . random ( ) < p ) : cs . append ( 'd' ) else : cs . append ( 'i' ) return cs
create a random threshold sequence of size n .