Refactorig randomise and adding tests