code: def add_efac(psr, efac=1.0, flagid=None, flags=None, seed=None):
      
      
      if seed is not None:
          N.random.seed(seed)
  
      # default efacvec
      efacvec = N.ones(psr.nobs)
  
      # check that efac is scalar if flags is None
      if flags is None:
          if not N.isscalar(efac):
              raise ValueError('ERROR: If flags is None, efac must be a scalar')
          else:
              efacvec = N.ones(psr.nobs) * efac
  
      if flags is not None and flagid is not None and not N.isscalar(efac):
          if len(efac) == len(flags):
              for ct, flag in enumerate(flags):
                  ind = flag == N.array(psr.flagvals(flagid))
                  efacvec[ind] = efac[ct]
  
      psr.stoas[:] += efacvec * psr.toaerrs * (1e-6 / day) * N.random.randn(psr.nobs)
docs: Add nominal TOA errors, multiplied by `efac` factor.
      Optionally take a pseudorandom-number-generator seed.