changed algorithm to have random input