Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to generate unique number?

 
xiaoyi hou
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a server support muliple client connections, the clients create some objects and store them on the server, these objects should be each assigned a unique number. my question is how to generate them, by who, server or client?
thank you
X HOU
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would think that the server should assign the unique numbers since it is the central repository for the objects.
 
xiaoyi hou
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marilyn deQueiroz:
I would think that the server should assign the unique numbers since it is the central repository for the objects.

but how?
 
Matthew Margolis
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are saving this info to a file or files you could generate a random number or better yet to insure no duplicates use the time and date as the filename. If you have the user creating multiple files at one time then you could use the date + time + a number representing that files contents (eg 11180105309 where 11 18 01 is the date 05 30 is the time and 9 is the number you are using to signify what particular object you are representing in that file.
[This message has been edited by Matthew Margolis (edited November 19, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic