Implement shuffle algorithm