775 snippets from 1604 members, and growing!
|
login
|
join
about
bytebin
members
tags
snippets
join
Snippets
Submit a Snippet
Search Snippets
New Snippets
Top Snippets
Top Tags
PHP
(138)
JavaScript
(125)
Java
(66)
VBSCRIPT
(58)
String
(44)
CSS
(31)
CSharp
(28)
File
(28)
HTML
(27)
mysql
(25)
C
(24)
VB.NET
(24)
python
(24)
CPlusPlus
(23)
groovy
(23)
New Snippets
Shell keepalive t...
Clean PHP Templat...
PHP/MySQL impleme...
Analyte - Easy to...
Easy SQLite inter...
Very lightweight ...
AutoComplete plug...
AutoComplete plug...
Connection Java -...
View PostgreSql
Venture Capital Jobs
New Members
KennethCC
me
jamesmcm
Can
Kelmi
ysg
dannymo2
chorny
wallie
Hackdemian
Top Members
dannyboy
sundaramkumar
mattrmiller
Pio
i_kenneth
ASmith
ctiggerf
sehrgut
bertheymans
SCoon
Home
/
Snippets
/
Generate UID
Generate UID
Snippet Menu
Revisions
Comments
Related Snippets
Add to Favorites
Email Snippet
Download Snippet
Print Snippet
Blog Snippet
snippet
|
revisions
|
comments
|
related
|
Add to Favorites
|
email
download
|
print
|
blog it
6
Tue. Apr. 25th, 2006 1:03 PM
1 of 1
mattrmiller
Generate
|
Java
|
UID
3 comments
Another way to generate a unique ID.
public
static
String
getUID
(
)
{
return
String
.
valueOf
(
System
.
currentTimeMillis
(
)
)
;
}
Matthew R. Miller
www.bluecreststudios.com
=================
Matthew R. Miller
http://bluecreststudios.com
http://www.codeandcoffee.com
Comments
New Comment
Dangerous code
Sat. Oct. 28th, 2006 1:57 PM
SCoon
This code is too dangerous. It is extremely unsafe in multithread applications and in applications that call this method too frequently (more that once in 1 ms).
Reply
Example
Fri. Jul. 14th, 2006 6:18 AM
SurfMan
Here's a nice one too:
http://www.javaexchange.com/aboutRandomGUID.html
Reply
Not quite a UID... (misses the "U" bit) ;-)
Thu. Apr. 27th, 2006 7:20 AM
TimYates
That's not strictly speaking a UID though, and it
could
be kinda dangerous to suggest it is...
a) It can be called twice during the same millisecond
b) It can be called twice simultaneously on multi-processor machines
Something like this would be more secure imho
public
static
String
getUID
(
)
{
return
new
java.
rmi
.
server
.
UID
(
)
.
toString
(
)
;
}
Reply
New Comment
Voting
Votes Up
ASmith
bertheymans
dannyboy
i_kenneth
napyfab
Pio
RatNuShock
rugi
sundaramkumar
Votes Down
afsina
java_junkie
SCoon
http://www.javaexchange.com/aboutRandomGUID.html
a) It can be called twice during the same millisecond
b) It can be called twice simultaneously on multi-processor machines
Something like this would be more secure imho
public static String getUID()
{
return new java.rmi.server.UID().toString() ;
}