Results 1 to 7 of 7
  1. #1
    ajw1993 is offline Member
    Join Date
    Nov 2012
    Posts
    30
    Rep Power
    0

    Default Storing unique random numbers

    Im trying to store only random numbers in an map , but when the id is stored i dont want that one to be used again , so when another customer is added i dont want them to use one that has already been used.
    this is my code >
    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
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Storing unique random numbers

    Why does it have to be random? Can't you use a sequence?

    To how many sites have you posted this question?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    ajw1993 is offline Member
    Join Date
    Nov 2012
    Posts
    30
    Rep Power
    0

    Default Re: Storing unique random numbers

    it has to be 2 letters than 6 random genertated numbers , but once the id has been used it cant be used again and can only be stored once

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Storing unique random numbers

    Why does it have to be random? Can't you use a sequence?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    ajw1993 is offline Member
    Join Date
    Nov 2012
    Posts
    30
    Rep Power
    0

    Default Re: Storing unique random numbers

    nope cz theres a lot of customers that have to be added and numbers have to be randomally generated by a system they dont choose they own

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,173
    Rep Power
    20

    Default Re: Storing unique random numbers

    That still doesn't explain why it has to be random.
    You could just have a counter.
    That way you could ensure that each had a unique id, without all the faffing about with checking whether a random number was already used.

    In any case, create a class that does this job, including holding the current list of used numbers.
    Give it the job of creating a unique random id.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,015
    Rep Power
    10

    Default Re: Storing unique random numbers

    How to Ask Questions the Smart Way
    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 New To Java
    Replies: 1
    Last Post: 03-23-2013, 06:25 PM
  2. I need help storing numbers in loops
    By MrPosotive in forum New To Java
    Replies: 26
    Last Post: 10-10-2012, 06:55 AM
  3. help w/ storing/scanning numbers in arrays
    By clemsontigers in forum New To Java
    Replies: 2
    Last Post: 03-30-2011, 07:46 AM
  4. Replies: 8
    Last Post: 04-19-2009, 06:50 PM
  5. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 11:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •