I am trying to create a program to create an arbitrary account name for a user. The user clicks the button and he copies the account name to the clipboard. The GUI component works, but I just can't come up with a better way to handle random string generation.
Allowed characters in the username: AZ az _
There are no numbers, other characters and two identical characters in a string.
Must be six in length.
My idea:
create an array of characters: [ _, a, b, c, d ... etc ] Generate a random integer between 0 and array.length - 1 and pick the letter in that slot. Check the last character to be added into the output String, and if it the same as the one we just picked, pick again. Otherwise, add it to the end of our String. Stop if the String length is of length six.
Is there a better way? Perhaps with regex? I have a feeling that I think doing it here is very bad.
source share