if you do something like:
a=torch.arange(20)
length=5
for x in range(10):
    index=random.randint(0, a.numel()-length)
    sample=a[index:index+length]
    print(sample)

each sample shares memory with a.
I’m not sure what you mean about no loops though, what do you want to do with each sample? If you need the results to be in a single tensor (e.g. with a batch dimension), it might be harder to share memory.