Re: [nyphp-talk] generate random unique 8-digit number

2009-03-13 Thread Daniel Convissor
On Tue, Mar 10, 2009 at 07:23:56PM -0400, Tim Gales wrote: > md5(uniqid(rand(), true)) Though MD5 collisions are possible, so I wouldn't count on that always resulting in a unique id. --Dan -- T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y data intensive web a

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-11 Thread Michael B Allen
On Wed, Mar 11, 2009 at 6:16 PM, John Campbell wrote: > On Wed, Mar 11, 2009 at 5:01 PM, Fernando Gabrieli > wrote: >> dont forget that md5($anyString) can return two hashes with the same value >> (if you have a db with 1,000,000 entries using this, it may happen) > > The odds of an MD5 collisio

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-11 Thread John Campbell
On Wed, Mar 11, 2009 at 5:01 PM, Fernando Gabrieli wrote: > dont forget that md5($anyString) can return two hashes with the same value > (if you have a db with 1,000,000 entries using this, it may happen) The odds of an MD5 collision with 1,000,000 entries is 0.0001% That

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-11 Thread Fernando Gabrieli
dont forget that md5($anyString) can return two hashes with the same value (if you have a db with 1,000,000 entries using this, it may happen) best, fernando On Wed, Mar 11, 2009 at 5:12 AM, Artur Marnik wrote: > Joey Derrico wrote: > >> One possibility would be to make a DB table with 2 column

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Michael B Allen
On Mon, Mar 9, 2009 at 9:56 PM, chad qian wrote: > Hi, > I need to generate random 8-digit numbers continuously.And no > duplication among all those numbers.In other word,every single 8-digit > number must be unique.How to do php programming? Just to give a little different answer from what peopl

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Artur Marnik
Joey Derrico wrote: One possibility would be to make a DB table with 2 columns. One where each row has a value from through , and the other column marked as for used. When you need to generate the random number you can query the database for each # not currently used and select

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Joey Derrico
One possibility would be to make a DB table with 2 columns. One where each row has a value from through , and the other column marked as for used. When you need to generate the random number you can query the database for each # not currently used and select randomly from the v

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Tim Gales
Chris Snyder wrote: Doing something like $random = $microtime . "_" . rand( 0, 256 ); gives you non-repeating pseudo-randomness. md5(uniqid(rand(), true)) // as suggested in the manual is harder to guess -- but now you're talkin' 32 chars. (as usual it depends on what you're tryin' to do) --

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Chris Snyder
On Tue, Mar 10, 2009 at 11:54 AM, Dan Cech wrote: > Chris Snyder wrote: >> Add a random number to a sufficiently deep timestamp (microseconds) >> and you will have a non-repeating random number. But you can't shorten >> it to 8 characters or whatever -- you have to keep the full timestamp >> in or

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Rolan Yang
Dan Cech wrote: ... If you're trying to generate relatively short pseudo-random IDs to thwart guesses, then the simplest method is going to be the previously-recommended approach of generating a random number and checking if it has already been used, rinse and repeat until you find one that has

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Edward Potter
Even the numbers game is not random. Some lotto numbers have come up 10X then others. It's the ink on the ball. Shifts the weight. But back to reality, you can get a pretty decent random number, for all practical purposes using the tips covers in this discussion. On Tue, Mar 10, 2009 at 11:54 AM

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Dan Cech
Chris Snyder wrote: > Add a random number to a sufficiently deep timestamp (microseconds) > and you will have a non-repeating random number. But you can't shorten > it to 8 characters or whatever -- you have to keep the full timestamp > in order to maintain non-repeatability. Not really, if you ad

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Chris Snyder
On Tue, Mar 10, 2009 at 11:15 AM, Edward Potter wrote: > > Go down to Prince & Broadway, stop the first model that walks by, then the > next, etc.  Ask them for a random number.  Believe me you will NEVER get the > same number twice. And they will never repeat! All laws of Physics go > straight ou

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Edward Potter
Well, it's easy. Go down to Prince & Broadway, stop the first model that walks by, then the next, etc. Ask them for a random number. Believe me you will NEVER get the same number twice. And they will never repeat! All laws of Physics go straight out the window. Even Einstein gave in. Just my 2

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Fernando Gabrieli
using tim's idea: get a uniqid, convert it to numbers and shift the difference :) - get a uniqid - convert the chars to numbers using php.net/ord - use the 8 first numbers (would be an alternative to rand() for 8-digits) On Tue, Mar 10, 2009 at 9:48 AM, Tim Gales wrote: > chad qian wrote: >

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Tim Gales
chad qian wrote: Hi, I need to generate random 8-digit numbers continuously.And no duplication among all those numbers.In other word,every single 8-digit number must be unique.How to do php programming? Change your specification to 13 characters and use the function uniqid Uniqid is driven by

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-10 Thread Fernando Gabrieli
the easiest: $isInUse = 0 ; while ($isInUse == 0) { $yourNumber = rand(0,9) . rand(0,9) . rand(0,9) (8 times) /* check here if $yourNumber is already in use and save the value in $isInUse */ } without saving the previous you will never be sure if you have duplicates best, fernando On

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-09 Thread Christopher R. Merlo
On Mon, Mar 9, 2009 at 9:56 PM, chad qian wrote: > Hi, > I need to generate random 8-digit numbers continuously.And no > duplication among all those numbers.In other word,every single 8-digit > number must be unique. > It is not mathematically feasible to continuously generate unique random num

Re: [nyphp-talk] generate random unique 8-digit number

2009-03-09 Thread David Krings
chad qian wrote: Hi, I need to generate random 8-digit numbers continuously.And no duplication among all those numbers.In other word,every single 8-digit number must be unique.How to do php programming? Thanks a lots! chad How random are you aiming for? As far as I know none of the progra

[nyphp-talk] generate random unique 8-digit number

2009-03-09 Thread chad qian
Hi, I need to generate random 8-digit numbers continuously.And no duplication among all those numbers.In other word,every single 8-digit number must be unique.How to do php programming? Thanks a lots! chad _ Express your pe