#NEWLINE# def random_insert( circuit , choices , seed = None ) : #NEWLINE# #INDENT# 'Insert a circuit into another quantum circuit.\n\n    random_insert randomly chooses a location in the circuit to insert\n    a randomly selected circuit from amongst the given choices.\n\n    Parameters\n    ==========\n\n    circuit : Gate tuple or Mul\n        A tuple or Mul of Gates representing a quantum circuit\n    choices : list\n        Set of circuit choices\n    seed : int or list\n        seed used for _randrange; to override the random selections, give\n        a list two integers, [i, j] where i is the circuit location where\n        choice[j] will be inserted.\n\n    Notes\n    =====\n\n    Indices for insertion should be [0, n] if n is the length of the\n    circuit.\n    ' #NEWLINE# from sympy.utilities.randtest import _randrange #NEWLINE# if ( not choices ) : #NEWLINE# #INDENT# return circuit #NEWLINE# #UNINDENT# if isinstance ( circuit , Mul ) : #NEWLINE# #INDENT# circuit = circuit . args #NEWLINE# #UNINDENT# randrange = _randrange ( seed ) #NEWLINE# loc = randrange ( ( len ( circuit ) + 1 ) ) #NEWLINE# choice = choices [ randrange ( len ( choices ) ) ] #NEWLINE# circuit = list ( circuit ) #NEWLINE# circuit [ loc : loc ] = choice #NEWLINE# return tuple ( randrange )