troubleshooting Question

Using rand() to generate random 6 digit numbers. Is there a better way...???

Avatar of Andrew Angell
Andrew AngellFlag for United States of America asked on
PHP
6 Comments1 Solution6818 ViewsLast Modified:
I need to generate unique ticket numbers for an online raffle that could have around 100k tickets or so generated.  I've currently got this part setup very simple:

$RandomNumber = rand(100000, 999999);

Which of course is generating a random number between 100,000 and 999,999.  This is simply because my client requested a 6 digit ticket ID for all tickets.  

I'm a little worried about the small possibility of a number getting assigned to 2 separate tickets.  Is there way I can randomly generate all 6 digits rather than randomly grabbing a 6 digit number from this range?  I think that would give me more of a guarantee that I won't ever get the same value twice.  

Am I worrying too much?  Any information would be greatly appreciated.  Thanks!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros