@Simone256 try like the following:
dataset = torchvision.datasets.MNIST('./datasets/', train=True, transform=torchvision.transforms.ToTensor())
random_train_loader = torch.utils.data.DataLoader(
        dataset,
        batch_size=batch_size,
        sampler=torch.utils.data.sampler.RandomSampler(dataset, replacement=True)
    )
for input_images, labels in iter(random_train_loader):

You should pass the instance of the dataset to the Random Sampler and not the class.