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:
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.