I was in a training course last week where the below code was used as part of an example. It was described as a method that would generate a unique ID and add the specified prefix to it.
public static String generateId(String prefix)
{
int randomNumber = new Random().nextInt();
String id = Integer.toString(randomNumber);
if(id.startsWith("-"))
{
id = id.replace('-', '3');
id = prefix + id;
}
return id;
}
Apart from the flaws that I'm sure you'll spot, I should point out that this was in the context of server-side code that forms part of a workflow. So depending on how often the workflow executes, it could be likely that multiple instances of the workflow would execute at the same time and generate the same "unique" ID.
What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake.