random - Java: Randomly generate distinct names - Stack Overflow
[Java] I wrote a random name generator
Generate Heroku-like random names to use in your Java applications (github.com/atrox/haikunatorjava)
Any thoughts on why you went with a Map<String,Object> for configuration instead of a builder, a configuration object, or a set of constructors? I suspect you are using a Map in order to mimic Ruby's option hash, but this isn't idomatic Java and seems a bit error-prone. If you must use the Map for configuration, I'd at least provide some constants. Or an enumeration and change the configuration to Map<MyEnum,Object> to constrain the types. But I'd see about losing the Map in favor of something else.
Also, it would be nice to provide a way to actually change the words being used. Hard coding them into the app doesn't provide as much value. As a user, I should be able to configure the word lists.
Don't let this discourage you, keep working.
Edit: If you are only using one method (StringUtils.join) from Apache Commons, I'd consider dropping the dependency and writing my own join method. But that's fairly subjective and I don't like having many dependencies if I can avoid them.
More on reddit.comName generator and several bugs
So you need to format your code and give a more specific issue. You made the class but put nothing inside it but maybe you left that out. Anyway Character is already a thing in Java so maybe first try a new name.
More on reddit.comI am answering this very late, but this is what really useful for new reader. This is a very simple and efficient way to get random VALID names. To do so, add maven repository in POM.xml
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>0.12</version>
</dependency>
And then use the Faker class as below in your Java code
Faker faker = new Faker();
String name = faker.name().fullName();
String firstName = faker.name().firstName();
String lastName = faker.name().lastName();
String streetAddress = faker.address().streetAddress();
Try printing the result using standard System.out.println();
For more reference Faker Lib
// class variable
final String lexicon = "ABCDEFGHIJKLMNOPQRSTUVWXYZ12345674890";
final java.util.Random rand = new java.util.Random();
// consider using a Map<String,Boolean> to say whether the identifier is being used or not
final Set<String> identifiers = new HashSet<String>();
public String randomIdentifier() {
StringBuilder builder = new StringBuilder();
while(builder.toString().length() == 0) {
int length = rand.nextInt(5)+5;
for(int i = 0; i < length; i++) {
builder.append(lexicon.charAt(rand.nextInt(lexicon.length())));
}
if(identifiers.contains(builder.toString())) {
builder = new StringBuilder();
}
}
return builder.toString();
}
Hey there! I recently started learning java a couple weeks ago as my first language, mostly out of interest in developing some mods for minecraft. After getting comfortable with java, I intend to learn C# and pursue other interests involving game development.
At any rate, I've always loved coming up with unique names. So I thought why not challenge myself with writing a random name generator that doesn't just spit out nonsense. I feel comfortable calling the project complete for now although I could add more and more functionality, I do want to get on with continuing to learn.
I would appreciate feedback on my coding, even if it's a fairly simple project. Am I doing things moderately well? Does anything stand out as potentially problematic in the future if I carry on the way I have here? Am I writing too much useless or needless code? I am trying to ensure I don't solidify any bad habits or practices while I'm still learning fresh.
The project is at https://github.com/Vember/RandomNameGenerator
Greatly appreciate any feedback!