Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 14th, 2002, 08:30 AM
Pupeno Pupeno is offline
Give peace a chance.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: Buenos Aires, Argentina
Posts: 83 Pupeno User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 39 sec
Reputation Power: 8
Send a message via ICQ to Pupeno Send a message via AIM to Pupeno Send a message via MSN to Pupeno Send a message via Yahoo to Pupeno
random ID numbers

I'm making a system and I've found a problem that I didn't realize I had.
There's a tool in this system too add new users, blank users that will be filled later, this users are records in a mysql database and the ID of this users have to be random. Any idea of how can I make it ?
I mean, I have to alocate N (N provided by the user) random ID numbers which are inside a range K:L (K and L provided by the user) which are not in the database yet.
I think there wouldn't be any problem since they're specting about 2000 users and the comon range is from 1000 to 9999 (and the database supports more a really great range).
any tip ? any hint ?
Thank you.
PS: this will be done in PHP with MySQL

Reply With Quote
  #2  
Old July 15th, 2002, 09:28 AM
dcaillouet's Avatar
dcaillouet dcaillouet is offline
Big Endian
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2001
Location: Fly-over country
Posts: 1,173 dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level)dcaillouet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 16 h 29 m 5 sec
Reputation Power: 24
One quick solution would be to have a table that holds all the ID numbers and a flag to show whether that ID has been used yet. If the user said he needed 2000 ID numbers between 1000 and 9999, you would populate the table with 2000 random numbers within that range. Each time an ID number was needed, you would select a number from the ID table whose "in use" flag hadn't been set yet and then set that "in use" flag to true for that ID number. You could also select the numbers from the table in a random order so that the random numbers in the table would not be used in sequential order. This would also lessen the chance of two users picking the same ID number from the table at the same time.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > random ID numbers


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT