Sign in to follow this  

Random name generator

This topic is 3111 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
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

This topic is 3111 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this