java - Generate Unique Object ID -


i'm trying generate new unique identifier each object in class, without using static nextid field increment. using create complications when unloading , unloading program.

i came solution loop through objects in static method checking them unknown reason me, won't exit while-loop.

i have been testing in ideone.com here trying create 5 objects begin with, though won't create one.

without having go link view whole testing code, below method i'm using.

public static int newrandomid() {     int randomid = 0;     boolean notunique = true;      while (notunique) {         randomid = (int) (math.random() * 999999 + 1);         (example e : examples) {             if (e.id == randomid) {                 notunique = true;                 break;             }             notunique = false;         }     }     return randomid; } 

have made stupid mistake i'm blind see, or there reason isn't working?

if need unique identifier (that need not sequential) , dosn't have integer, have @ java.util.uuid


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -