# Creating a 8 digit password mixture of numbers and letters

• November 28th, 2012, 01:21 PM
djl1990
Creating a 8 digit password mixture of numbers and letters
What i want to do is generate a random 8 digit password consisting of 8 characters.

The possible characters would be 0-9 and a-z.

Here is what i have so far but i will warn you i think i am going down the copmlete wrong road with this one:

Code :

```package latesttasks;   // Password Generator // 8 characters, can be; 0-9 and a-z   import java.util.Random;   public class Task6 {   public static void main(String[] args) {   // The 8 Random Numbers 0 to 35 int r1, r2, r3, r4, r5, r6, r7, r8; // The 8 individual characters String c1, c2, c3, c4, c5, c6, c7, c8; // The complete password - the 8 strings joined String complete; // The complete library of possible characters String[] characters = new String[]{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};   Random rand = new Random();   r1 = rand.nextInt(36); r2 = rand.nextInt(36); r3 = rand.nextInt(36); r4 = rand.nextInt(36); r5 = rand.nextInt(36); r6 = rand.nextInt(36); r7 = rand.nextInt(36); r8 = rand.nextInt(36);     } }```

............ What my plan was was to create a String array to hold each individual character 0-9 and a-z.

Then create 8 random numbers using Random(36) (which is a random number 0 to 35)

Each of the random numbers would be used as the index to get a character from the array of characters i created. For example if the random number generated is 34, then that character would be the 34th index of the array.

So what I am stuck on is assigning the index's of the array to variables: c1, c2, c3, c4, c5, c6, c7, c8 Those variables represent character 1, character 2 etc.

I was hoping i could of used something like this:

c1 = characters.charAt(r1)

where r1 is the random number generated to be used as the index number ?

I am really stuck on this.

What kind of Array do i need and what methods do i need to assign the random index numbers of the array to a new variable.
• November 28th, 2012, 01:35 PM
Norm
Re: Creating a 8 digit password mixture of numbers and letters
You index into an array and get a reference to one of its slots by using array notation: theArray[theIndex]
That reference to a slot can be used anywhere a variable is used.

Arrays do not have methods that can be called: characters.charAt(r1)
that statement looks like it is trying to call the method charAt() using the object reference characters.

When you get compiler errors, you should copy and paste here the full text of the error message.
• November 28th, 2012, 02:45 PM
djl1990
Re: Creating a 8 digit password mixture of numbers and letters
Quote:

Originally Posted by Norm
You index into an array and get a reference to one of its slots by using array notation: theArray[theIndex]
That reference to a slot can be used anywhere a variable is used.

Arrays do not have methods that can be called: characters.charAt(r1)
that statement looks like it is trying to call the method charAt() using the object reference characters.

When you get compiler errors, you should copy and paste here the full text of the error message.

Thanks so for the first character it would be:

c1 = characters[r1];
• November 28th, 2012, 02:53 PM
Norm
Re: Creating a 8 digit password mixture of numbers and letters
That looks ok. Compile and execute it and see what ends up in c1 by printing c1.