For Programmers: Free Programming Magazines  


Home > Archive > PHP on Windows > June 2005 > Re: [PHP-WIN] how to avoid repetition?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-WIN] how to avoid repetition?
graeme

2005-06-10, 3:58 am

A couple of ideas to improve the chances of generating unique strings

You could create 20,000,001 char(6) strings, merge the first with the
last, second with the second last and so on, creating char(12) strings

or

You could create 20,000,001 char(7) strings, merge the first with the
last, second with the second last and so on, creating char(14) strings
and then dropping two digits at random.

BUT if you must guarantee that the strings are unique then you will need
to do a comparison of the resulting strings. Using a database to sort
and then compare is as good an approach as any, since database have good
sorting algorithms and are designed to manage large numbers.

graeme.

bo wrote:

>I need to generate 10million 12-char string and I am able to do so, however
>the problem is how to avoid repetition keeping each string unique? it will
>be a disaster to compare each string,isn't it?
>
>ps Thanks Yong.
>
>Bo
>
>
>


--
Experience is a good teacher, but she sends in terrific bills.

Minna Antrim
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com