Updating random algorithm for better performance