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