Jump to content
  • Advertisement
Sign in to follow this  
Dieseltjuh

Random name generator

This topic is 3328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I am creating a random name generator, and its going well so far. However, I want to have unique names. The problem is, the more names I create, the higher amount of duplicates are being generated. Is there a simple way too keep iterating until you have a full array of unique names ? I wrote a function which checks for duplicate names, and when generating 8K names I have somewhere between 100-200 duplicates. If needed, ill post my code, but I don't think its needed since its more of a theory question.

Share this post


Link to post
Share on other sites
Advertisement
Use a set structure like C++'s std::set class or Python's set object and add names to the set until it reaches the size you want.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dieseltjuh
why would that not create duplicates then? o.O


A set, by definition, doesn't contain duplicates. So you randomly generate the name, add it to the set, and repeat until the set reaches a particular size.

The duplicates are still created, but the set will contain only the unique names.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Use a set structure like C++'s std::set class or Python's set object and add names to the set until it reaches the size you want.

You just have to make sure the size is less than the maximum number of unique values that can be generated by your RNG, otherwise it will never fill up :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!