Creating a new "ID" every time..

Discussion in 'Plugin Development' started by Epicballzy, Sep 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Epicballzy

    Whats a simple way to create a 4 digit ID? I'll be using the id to track "reports" players make. The one I have right now, only make 1 id, then if I make a new report, it just updates the one I already made.

    These ids are set in a config.

    This is what I have:
    Code:java
    1. private static final long LIMIT = 9999L;
    2. private static long last = 0;
    3.  
    4. public static long getID() {
    5. long id = System.currentTimeMillis() % LIMIT;
    6. if ( id <= last ) {
    7. id = (last + 1) % LIMIT;
    8. }
    9. return last = id;
    10. }


    (I haven't dealt with ids before ^.^)

    All help is appreciated!
     
  2. Offline

    zachoooo

    I'd just increment it each time. First report 0001, second report 0002, so on and so on. Don't over complicate anything.
     
  3. Offline

    Deleted user

    What about a UUID?
     
Thread Status:
Not open for further replies.

Share This Page