I don’t think you can ensure each dataset opens a different file. Especially since your negative sample seems to choose a random file / line in your entire dataset. This you need access to the entire set for random sampling.