문제

I've got a method that returns a string with predefined length of random alpha numbers.

I just let it run until it comes across a duplicate and breaks out of the loop and display the amount of generations it took before a duplicate was generated.

The loop numbers will be in the millions, and I am wondering if this really is good and efficient of testing it?

도움이 되었습니까?

해결책

You can use array_search

The function return the string and store it to an array. Then use array_search to see if it is not FALSE and loop.

다른 팁

Put The generated strings into an array as a key before outputting them.

$array[$alpha_string] = (isset($array[$alpha_string])) ? $array[$alpha_string] + 1 : 1;

Then check which items have a count > 1.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top