In addition to what Gavin said. You seem to want some form of key
perhaps to be able to identify the authenticity of your contest
winner. An auto increment ID won't be very secure for that, but you
still need it.
Take a known combination of perhaps the key, name, email address, etc,
and run a hashing function on it. Md5 will often suffice.
This will give you a unique hash that only you know how it was made.
You can inject some 'salt' into a known location to add more
difficulty in guessing your hashing input.
This hash will be asking too much of the user to hand type in, so I'm
assuming you will accept it via a link in a URL.
Or ask for whatever you used to make the hash and rehash that and
compare your internal stored result.
If not, for your needs you may be able to safely remove ambiguous
characters, and take a substring of it to make it shorter.
It's also quite easy to create a dictionary of words and create a
function that can make word1-xx-word2 and end up with red-56-car.
--
Scott
Iphone says hello.
On Oct 16, 2009, at 11:25 AM, Gavin Towey <gtowey@stripped> wrote:
> Don't try to give them a random number, instead use a table with a
> primary key that is AUTO_INCREMENT. Then you just insert the
> record, and afterwards SELECT LAST_INSERT_ID(); to retrieve the id
> for the record created.
>
> With random numbers, you're going to have more collisions when you
> add more records.
>
> Regards,
> Gavin Towey
>
> -----Original Message-----
> From: Ray [mailto:ray@stripped]
> Sent: Friday, October 16, 2009 8:43 AM
> To: mysql@stripped
> Subject: insert random number into table
>
> Hello All,
> I am trying to insert a unique random number* with each row when
> inserting
> into a table. I can do it in the application layer (php) but just
> wondering if
> there is an easier way in the database layer.
> Thanks
> Ray
>
> * for example, when registering a person for a contest, I want to
> give them a
> unique, random identifier.