On Friday 26 October 2001 10:00, Dana Holt wrote:
> Can I automatically generate a random, unique, integer value in a certain
> range when inserting data into a column using SQL?
>
> If so, how?

Random is easy.  Just find a good RNG (random number generator) somewhere 
(there are many available on the 'net, search on Google).  Or, use the RAND 
function that comes with MySQL.  You can find RNGs that have extremely long 
periods.

Unique is easy.  Just use an auto-increment field in MySQL.

Random _and_ unique are not that simple.

Grab a handy book on cryptography.  There are operations on numeric 
(bitstring) values that will do what you want starting with a guaranteed 
unique input (such as from an auto-increment field or a sequence).  The key 
thing to remember is that uniqueness and randomness can be derived in two 
steps, they need not be done in one.

Are you sure it needs to be "random"?  By definition, if it is unique, it 
can't be totally random since a random number would have a certain 
probability of being the same value twice after a certain number of samples.

Is there a simple SQL statement that will do what you want?  Probably not.

Best,
Kyle

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MicroTelco Services saves money on every Fax:
- Fax to email (FREE)
- Fax to PSTN based Fax (Up to 95% Savings)
- Fax Broadcasting: Send 100s of faxes to fax machines
and email addresses in the time it takes to send just one!
===========================================================
    So send a fax today and let us know what you think! 
       For more info. visit: www.internetfaxjack.com
===========================================================


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to