Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (6.1k points)

I want to create a random, 17 characters long, ID. I am giving an example over here "AJB53JHS232ERO0H1". There should be random ordering. I tried creating an array with letters A-Z and a 'check' variable that randoms to 1-2. And in a loop; 

Randomize 'check' to 1-2.

If (check == 1) then the character is a letter.

Pick a random index from the letters array.


Pick a random number.

Can I do it in an easier method?

1 Answer

0 votes
by (11.7k points)

Try out this solution given down below:

protected String getSaltString() {


        StringBuilder salt = new StringBuilder();

        Random rnd = new Random();

        while (salt.length() < 18) { // length of the random string.

            int index = (int) (rnd.nextFloat() * SALTCHARS.length());



        String saltStr = salt.toString();

        return saltStr;


By using this code above, you can generate a salt string for login purposes.

f you want to get more insights into SQL, check out this SQL Course from Intellipaat.

Related questions

0 votes
0 answers
+2 votes
2 answers
asked May 28, 2019 in Python by Ankita (170 points)
0 votes
1 answer

Browse Categories