Local var and torch.random()

Two small changes to make the usage safer.