Added function to randomly select training and validation sets