code: def noise_from_psd(length, delta_t, psd, seed=None):
      
      noise_ts = TimeSeries(zeros(length), delta_t=delta_t)
  
      if seed is None:
          seed = numpy.random.randint(2**32)
  
      randomness = lal.gsl_rng("ranlux", seed)
  
      N = int (1.0 / delta_t / psd.delta_f)
      n = N//2+1
      stride = N//2
  
      if n > len(psd):
          raise ValueError("PSD not compatible with requested delta_t")
  
      psd = (psd[0:n]).lal()
      psd.data.data[n-1] = 0
  
      segment = TimeSeries(zeros(N), delta_t=delta_t).lal()
      length_generated = 0
  
      SimNoise(segment, 0, psd, randomness)
      while (length_generated < length):
          if (length_generated + stride) < length:
              noise_ts.data[length_generated:length_generated+stride] = segment.data.data[0:stride]
          else:
              noise_ts.data[length_generated:length] = segment.data.data[0:length-length_generated]
  
          length_generated += stride
          SimNoise(segment, stride, psd, randomness)
  
      return noise_ts
docs: Create noise with a given psd.
  
      Return noise with a given psd. Note that if unique noise is desired
      a unique seed should be provided.
  
      Parameters
      ----------
      length : int
          The length of noise to generate in samples.
      delta_t : float
          The time step of the noise.
      psd : FrequencySeries
          The noise weighting to color the noise.
      seed : {0, int}
          The seed to generate the noise.
  
      Returns
      --------
      noise : TimeSeries
          A TimeSeries containing gaussian noise colored by the given psd.