I am taking an introductory programming course and need a bit of help. The assignment is to have the Java program read a message (I am assuming from a .dat file, not quite sure). The program creates substitutes each random letter with a different letter chosen at random by the computer. If the letter M is chosen to replace the letter P in the message, then M replaces P in every instance of the message.
Right now, I just need help with generating a set of the 26 letters ordered randomly without duplicates. Here is what I have:
Right now the program does nothing. If I remove the last for loop with j as the counter and everything within that for loop, I get an output of 26 letters randomly chosen, but there are duplicates. The last for loop is supposed to say something like, "If the randomly generated letter (substitute) has appeared before in substitute[], then generate a new random number until it is no longer a duplicate of a previous number, at which point the letter which corresponds to the random number is stored in substitute.
So if you could give me some suggestions it would be much appreciated. If I am overcomplicating things and there is a much easier way to do this, please guide me in the right direction.
Thanks,
Noah
EDIT: Spacing in the program code isn't working. Looks fine while I'm editing it though. What's wrong?
EDIT 2: See here for my code, correctly formatted.
Firefox is irrelevant in today's internet. Most websites don't work as smooth as any Chromium browsers. Web developers are monopolizing and responsible for this situation.
Tons in stock in all stores here in Norway... Doesn't seem that popular. I'm not buying either. Maybe when winter comes, but I'm not gonna waste my summer on being indoors and gaming.
Question
-Noah-
Hi guys,
I am taking an introductory programming course and need a bit of help. The assignment is to have the Java program read a message (I am assuming from a .dat file, not quite sure). The program creates substitutes each random letter with a different letter chosen at random by the computer. If the letter M is chosen to replace the letter P in the message, then M replaces P in every instance of the message.
Right now, I just need help with generating a set of the 26 letters ordered randomly without duplicates. Here is what I have:
Right now the program does nothing. If I remove the last for loop with j as the counter and everything within that for loop, I get an output of 26 letters randomly chosen, but there are duplicates. The last for loop is supposed to say something like, "If the randomly generated letter (substitute) has appeared before in substitute[], then generate a new random number until it is no longer a duplicate of a previous number, at which point the letter which corresponds to the random number is stored in substitute.
So if you could give me some suggestions it would be much appreciated. If I am overcomplicating things and there is a much easier way to do this, please guide me in the right direction.
Thanks,
Noah
EDIT: Spacing in the program code isn't working. Looks fine while I'm editing it though. What's wrong?
EDIT 2: See here for my code, correctly formatted.
Edited by -Noah-Link to comment
https://www.neowin.net/forum/topic/776712-java-generate-the-alphabet-in-random-order-no-duplicates/Share on other sites
32 answers to this question
Recommended Posts