<p>I would like to write a utility that will provide me with a relatively unique ID in Java.  Something pretty simple, like x bits from timestamp + y bits from random number.</p>

<p>So, how would I implement the following method:</p>

<pre><code>long getUniqueID()
{
    long timestamp = System.currentTimeMillis();
    long random = some random long

    ...

    return id;
}
</code></pre>

<p>BONUS</p>

<p>Any suggestions for other easily obtainable information I could use to form my ID?</p>

<p>note: I am aware of GUIDs and I know Java has a UUID class, but I don't want something that is 128 bits long.</p>

What you are trying to do is create a
hash function
that combines two long values into a single long value. In this case, the
uniformity
of the hash function will be of utmost importance since collisions in created unique ID values are unacceptable. However, if you can compare hash values to previously created identifiers, then collisions can be resolved by modifying the hash until no collision occurs.
For example, you could take the time stamp and perform an
exclusive-or
(using the caret ^ operator in Java) with the random value. If a collision is detected, then add one to the result.