Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Storing unique random numbers

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Storing unique random numbers

    Im trying to store random id's in my code , but im trying to figure out how to store only unique id's how would i do that ?

    public void storeCustomer (Customer newCustomer)
    {
    if(newCustomer.getCustomerID().equals("unknown"))
    {
    newCustomer.generatorCustomerID("ab-",6);

    customerMap.put(newCustomer.getCustomerID(),newCus tomer);
    }
    else
    {
    customerMap.put(newCustomer.getCustomerID(),newCus tomer);
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,167
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Storing unique random numbers

    How would you do this without a computer? Say you have a 100-sided die. You want to generate a list of 10 unique random numbers. What do you do?

    Write out instructions that you could hand to a stranger to have them accomplish the goal, and when you have that, you'll have an algorithm that you can implement.

    --- Update ---

    Nevermind, crossposted.

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/71377-storing-unique-random-numbers.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Storing unique random numbers

    well u do a id by string followed by 6 random numbers then adds to the map . but how would u just add n not use it again

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,167
    My Mood
    Hungover
    Thanks
    141
    Thanked 597 Times in 512 Posts

    Default Re: Storing unique random numbers

    I wouldn't use a Map. But since I don't know what help you've already received, I'm not going to waste my time repeating what you might have already heard.

    This is why we ask people not to crosspost, or to at least let us know when they do so.

    Good luck.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Storing random numbers into a String field
    By ajw1993 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 23rd, 2013, 10:44 AM
  2. Can't get seven random numbers, only one.
    By alpvii in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 6th, 2010, 04:39 PM
  3. help w/ storing/scanning numbers in two dimensional arrays
    By robertsbd in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 1st, 2010, 10:56 PM
  4. help w/ storing/scanning numbers in arrays
    By robertsbd in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 17th, 2010, 09:55 PM
  5. Random numbers
    By Pooja Deshpande in forum Java SE APIs
    Replies: 8
    Last Post: June 5th, 2009, 04:36 AM