def random_lobster(n, p1, p2, seed=None):
 if (seed is not None):
  random.seed(seed)
 llen = int((((2 * random.random()) * n) + 0.5))
 L = path_graph(llen)
 L.name = ('random_lobster(%d,%s,%s)' % (n, p1, p2))
 current_node = (llen - 1)
 for n in range(llen):
  if (random.random() < p1):
   current_node += 1
   L.add_edge(n, current_node)
   if (random.random() < p2):
    current_node += 1
    L.add_edge((current_node - 1), current_node)
 return L

def random_lobster ( n , p1 , p2 , seed = None ) : if ( seed is not None ) : random . seed ( seed ) llen = int ( ( ( ( 2 * random . random ( ) ) * n ) + 0.5 ) ) L = path_graph ( llen ) L . name = ( 'random_lobster(%d,%s,%s)' % ( n , p1 , p2 ) ) current_node = ( llen - 1 ) for n in range ( llen ) : if ( random . random ( ) < p1 ) : current_node += 1 L . add_edge ( n , current_node ) if ( random . random ( ) < p2 ) : current_node += 1 L . add_edge ( ( current_node - 1 ) , current_node ) return L
returns a random lobster graph .