Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1034665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:25:40+00:00 2026-05-16T14:25:40+00:00

I am having problems taking in a string (a persons name), and getting back

  • 0

I am having problems taking in a string (a persons name), and getting back a unique integer, it keeps going through the catch function, and I dont know why, other than the way I wrote SecureRandom is not working, but it is very confusing. I am very new to programming so please be kind!

  public static int uinqueID(String name){
    try{
      SecureRandom srA = SecureRandom.getInstance(name);
      Integer randomA = new Integer(srA.nextInt());
      System.out.println(randomA);
      UUID uuidA = UUID.randomUUID();
      String randomNum2 = uuidA.toString();
      System.out.println(randomNum2);
      int randomB = Integer.valueOf(randomNum2);
      int uniqueID = randomA + randomB;
      return uniqueID;
    } catch(NoSuchAlgorithmException e) {
      System.err.println("I failed");
    }
    return -1;
  }

The output I am getting is:
I failed
-1

Thank you for your help!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:25:41+00:00Added an answer on May 16, 2026 at 2:25 pm

    You cannot use the name of the person to get a SecureRandom object. It expects the name of in implementation of a random number generator. You can use “SHA1PRNG” as that is default available. You can then seed the random generator with the name.getBytes() and then get the next random number.

    From the Javadoc:

    public static SecureRandom getInstance(String algorithm)
    throws NoSuchAlgorithmException

    Generates a SecureRandom object that …snip…

    Parameters:
    algorithm – the name of the PRNG algorithm. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard PRNG algorithm names.

    Returns:
    the new SecureRandom object.
    Throws:
    NoSuchAlgorithmException – if the PRNG algorithm is not available in the caller’s environment.
    Since:
    1.2

    You can skip the rest because the hash is as good as the algorithm and adding other things to it hardly make it more secure.

    something like :

    static int getUUID(String name) throws NoSuchAlgorithmException {
        SecureRandom srA = SecureRandom.getInstance("SHA1PRNG");
        srA.setSeed(name.getBytes());
        return new Integer(srA.nextInt());
    }
    

    I would have normally used a MessageDigest, but I must admit this is pretty tight.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having problems with a method in a class file: public static function getPageLeft($pid)
Im having problems getting at the HTML5 video tag with jQuery. Here is my
Taking a rails tutorial, and I've run into the following problem that I'm having
Having problems with a small awk script, Im trying to choose the newest of
Having problems iterating. Problem has to do with const correctness, I think. I assume
Having problems with the combining of two statements in a controller. Both statements work
Im having problems with displaying ONLY some elements ONLY on print page. For example
Im having problems with classpaths. I have used them before with import but I'm
im having problems starting a codeigniter project, the problem is that when i do
im having problems on how to save the content of an array in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.