#Generating a string of random letters, without repeating

8 messages · Page 1 of 1 (latest)

red jolt
#

I am trying to generate a list of random letters of the English alphabet without using the same letter twice.
This code currently makes a list of random letters but there is a chance that letters are repeated... how could I avoid using the same letter twice?

                        for (int i = 0; i < 8; i++) 
                        {
                            char c = (char)(rand.nextInt(26) + 65);
                            code += c;
                        }
                        break;
wicked wigeonBOT
#

This post has been reserved for your question.

Hey @red jolt! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

fiery thicket
#

you should check either that character is in string already

red jolt
#

what would be a good way do do this....

fiery thicket
#

like ```java
while (counter < 8)
char c = generate
if (word.indexOf(c) != -1)
continue;
word += c;
counter++;

red jolt
#

thanks boss

wicked wigeonBOT
# red jolt thanks boss

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.