RE: how to avoid repetition?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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?

One way to handle this would be to insert the 10 million values into a MySQL
table [1] that has one varchar(12) field with no indexes.

Then, once the records are in the table, issue the following sql statement:

ALTER IGNORE TABLE lotsofids ADD UNIQUE INDEX(random_id)

This will effectively remove any duplicate entries from the table, and then
a:

SELECT COUNT(*) FROM lotsofids 

... would tell you if you need to generate any more ids to 'top up' the
table to 10 million. It will also give you some idea of how effective the
randomization process you're using to generate the values is.

Assumptions made above:

- Your table name is 'lotsofids' and your field name is 'random_id'.
Obviously, you can change these to whatever you prefer.

Regards,

Murray

[1] Assuming you have MySQL available -- a google on whichever db server you
have using keywords "remove duplicates <insert name of db server here>"
should bring up similar methods

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux