I want to make a Nepali Random Name Generator

  • Thread starter shivajikobardan
  • Start date
  • Tags
    Random
In summary, the conversation discusses the idea of generating random names using JavaScript for a project. The speaker mentions using a list of Nepali names for the project and asks if it can be done in vanilla JS or if they need to use node.js or React.js. The responder suggests using a stand-alone function for loading remote files into an array and also suggests using JavaScript classes for additional learning. They also provide an example of how to load files and handle errors.
  • #1
shivajikobardan
674
54
TL;DR Summary
Random Name Generator
What's the full process for it? Don't I need an API for names? We don't have that yet. So, how will I do this? Can you guide me step by step? without telling me any code? I'm planning to do this in javascript so that I can deploy the application on the web(blogger).
 
Technology news on Phys.org
  • #2
Make an array of first names and an array of last names. Use a random number generator to get an index into the firstname array and a second call to get an index into the lastname array.
 
  • Like
Likes Vanadium 50 and shivajikobardan
  • #3
jedishrfu said:
Make an array of first names and an array of last names. Use a random number generator to get an index into the firstname array and a second call to get an index into the lastname array.
great idea. Thank you. This will be my weekend's project. Hopefully I finish it.
 
  • #4
This works provided first and last names have no correlation. In the US, Yo-yo Ma is a plausible name, as is Mordecai Shapiro, but Yo-yo Shapiro would be unlikely.
 
  • #5
We do have people who combine their given first name with their married name to get the blended cultural name.

Yoko Lennon vs Yoko Ono are often used interchangeably.
 
Last edited:
  • #6
TL;DR Summary: Random Name Generator
shivajikobardan said:
What's the full process for it? Don't I need an API for names? We don't have that yet. So, how will I do this? Can you guide me step by step? without telling me any code? I'm planning to do this in javascript so that I can deploy the application on the web(blogger).
The main reason for that disagreement is the underdefined OP of yours. What are the requirements of this assignment? How believable do the names need to be? Can they be complete gibberish, or can they be combinations of first and last names that make no sense, like Fred Shivajikobardan?

Please restate your OP with much better parameters on the types of names that you want to generate. If you tried to register here at PF as Fred Shivajikobardan I can guarantee that our PF AI would put that registration application into the Mentor Queue for Moderation...
 
Last edited by a moderator:
  • #7
https://github.com/techgaun/nepali-names
Here're Nepali Names(first name only). I want to just display first name of male and female.
In the future, I plan to build a site which generates a baby name when given father and mother name.
 
  • Like
Likes jedishrfu
  • #8
If you just want to draw a random first name then you only need to store all of them in an accessible way, e.g. a file with one name per line. Do separate files with male and female names if you want to distinguish them. Your data source already has these files prepared. Draw a random number from 1 to the number of names, pick the corresponding line.
 
  • #9
do I need to use nodejs->Thus react js for file processing? Can this be done in vanilla js? This honestly sounds like a simple but interesting and useful project idea. If I want to incorporate random name recommendations based on the name of mother and father, what should I learn and use for it?
 
  • #10
shivajikobardan said:
do I need to use nodejs->Thus react js for file processing?
No.

shivajikobardan said:
Can this be done in vanilla js?
Yes.

shivajikobardan said:
This honestly sounds like a simple but interesting and useful project idea.
I agree. Although you don't need to implement this using JavaScript classes, this might be a useful additional learning point for you. Loading files in the browser is not trivial so I'll do that bit for you to give you a head start.

JavaScript:
// This is a stand-alone function to do the 'heavy lifting' of loading a remote
// file into an array.
const load = async (url) => {
  const response = await fetch(url);
  if (!response.ok) throw new Error('Not found');
  const fileContent = await response.text();
  return fileContent.split(/[\n\r]+/);
};

class NameSelector {
  static STATE_LOADING = 'loading';
  static STATE_LOADED = 'loaded';
  static STATE_ERROR = 'error';

  femaleNames = [];
  maleNames = [];
  state = null;

  async loadNames() {
    try {
      this.state = NameSelector.STATE_LOADING;
      // If using these files be sure to respect the terms of use of jsDelivr
      // https://www.jsdelivr.com/terms and the rights of the author at
      // https://github.com/techgaun/nepali-names.
      [this.femaleNames, this.maleNames] = await Promise.all([
        load('https://cdn.jsdelivr.net/gh/techgaun/nepali-names/female.txt'),
        load('https://cdn.jsdelivr.net/gh/techgaun/nepali-names/male.txt'),
      ]);
      this.state = NameSelector.STATE_LOADED;
    } catch (e) {
      this.state = NameSelector.STATE_ERROR;
      this.error = e;
    }
  }
}
 
Last edited:
  • Like
Likes berkeman
  • #11
shivajikobardan said:
do I need to use nodejs->Thus react js for file processing? Can this be done in vanilla js? This honestly sounds like a simple but interesting and useful project idea.
I haven't used javascript before, so I can't say anything about it. In general, you would read the names from a file into something like an array or list for quick retrieval, generate a random number which will be used as the index of the array, and then fetch whichever name is at that particular index in the array. Use different arrays for sexes, first and last names, regions, etc. This is an extremely simple program and shouldn't pose too much difficulty.

shivajikobardan said:
If I want to incorporate random name recommendations based on the name of mother and father, what should I learn and use for it?
That depends on how complex you're going to make things. If you just want the new name to have the same family name (surname) and new first (given) name then you'd just fetch a random first name and use the surname given/selected by the user. A similar method can be used if you want the new middle name to be based on the parents names.

If you have something more complicated in mind then the program would probably be substantially more complicated depending on what you want to implement.
 
  • Like
Likes jedishrfu
  • #12
pbuk said:
No.Yes.I agree. Although you don't need to implement this using JavaScript classes, this might be a useful additional learning point for you. Loading files in the browser is not trivial so I'll do that bit for you to give you a head start.

JavaScript:
// This is a stand-alone function to do the 'heavy lifting' of loading a remote
// file into an array.
const load = async (url) => {
  const response = await fetch(url);
  if (!response.ok) throw new Error('Not found');
  const fileContent = await response.text();
  return fileContent.split(/[\n\r]+/);
};

class NameSelector {
  static STATE_LOADING = 'loading';
  static STATE_LOADED = 'loaded';
  static STATE_ERROR = 'error';

  femaleNames = [];
  maleNames = [];
  state = null;

  async loadNames() {
    try {
      this.state = NameSelector.STATE_LOADING;
      // If using these files be sure to respect the terms of use of jsDelivr
      // https://www.jsdelivr.com/terms and the rights of the author at
      // https://github.com/techgaun/nepali-names.
      [this.femaleNames, this.maleNames] = await Promise.all([
        load('https://cdn.jsdelivr.net/gh/techgaun/nepali-names/female.txt'),
        load('https://cdn.jsdelivr.net/gh/techgaun/nepali-names/male.txt'),
      ]);
      this.state = NameSelector.STATE_LOADED;
    } catch (e) {
      this.state = NameSelector.STATE_ERROR;
      this.error = e;
    }
  }
}
thank you, my work is already reduced by 80%.
 
  • Like
Likes jedishrfu
  • #13
I made it.
JavaScript:
// This is a stand-alone function to do the 'heavy lifting' of loading a remote
// file into an array.
const load = async (url) => {
  const response = await fetch(url);
  if (!response.ok) throw new Error('Not found');
  const fileContent = await response.text();
  return fileContent.split(/[\n\r]+/);
};

class NameSelector {
  static STATE_LOADING = 'loading';
  static STATE_LOADED = 'loaded';
  static STATE_ERROR = 'error';

  femaleNames = [];
  maleNames = [];
  state = null;

  async loadNames() {
    try {
      this.state = NameSelector.STATE_LOADING;
      // If using these files be sure to respect the terms of use of jsDelivr
      // https://www.jsdelivr.com/terms and the rights of the author at
      // https://github.com/techgaun/nepali-names.
      [this.femaleNames, this.maleNames] = await Promise.all([
        load('https://cdn.jsdelivr.net/gh/techgaun/nepali-names/female.txt'),
        load('https://cdn.jsdelivr.net/gh/techgaun/nepali-names/male.txt'),
      ]);
      this.state = NameSelector.STATE_LOADED;
    } catch (e) {
      this.state = NameSelector.STATE_ERROR;
      this.error = e;
    }
  }
}const nameSelector = new NameSelector();

document.addEventListener("DOMContentLoaded", function () {
  const randomNameGenerator = document.getElementById("random-name-generator");
  //create a button to generate random name
  const generateButton = document.createElement("button");
  generateButton.textContent = "Generate Random Name";
  const randomNameDisplay = document.createElement("p");
  generateButton.addEventListener("click", function () {
    nameSelector.loadNames().then(() => {
      //console.log(nameSelector.femaleNames);
      //console.log(nameSelector.maleNames);
      const randomIndex = Math.floor(Math.random() * nameSelector.maleNames.length);
      const randomName = nameSelector.maleNames[randomIndex];
      randomNameDisplay.textContent = randomName;
    }).catch((error) => {
      console.error(error);
    });  });
  randomNameGenerator.appendChild(generateButton);
  randomNameGenerator.appendChild(randomNameDisplay);})
 
  • Like
Likes jedishrfu
  • #14
I will now make male and female name generator with 2 buttons. Wait a while. I made that as well. It's just few lines of code.
 
Last edited:
  • Like
Likes jedishrfu
  • #15
shivajikobardan said:
I made it.
Nice, your coding has improved lots!

If you are using loadNames() like that I think would change it to
JavaScript:
  async loadNames(force = false) {
    try {
      if (this.state === NameSelector.STATE_LOADED && !force) return;
      // ...
to avoid unnecessarily reloading.
 

1. How does a random name generator work?

A random name generator uses a set of rules and data to generate names that are not predetermined or based on any existing pattern. It typically uses algorithms and databases to generate unique combinations of letters, syllables, and sounds to create new names.

2. Can a Nepali random name generator generate authentic Nepali names?

Yes, a Nepali random name generator can generate authentic Nepali names as long as it has access to accurate and extensive data of Nepali names, including common first names, surnames, and meanings. It should also consider the cultural and linguistic aspects of the Nepali language.

3. How accurate are the names generated by a random name generator?

The accuracy of names generated by a random name generator largely depends on the quality and quantity of data used. A well-designed Nepali random name generator with a large and diverse database of names has a higher chance of generating accurate names. However, there may still be some rare or unusual names that the generator may not be able to produce.

4. Can a random name generator be customized to generate specific types of names?

Yes, a random name generator can be customized to generate specific types of names by adjusting the rules and data used. For example, if you are looking to generate only male or female names, you can set the generator to follow specific gender-based rules. Similarly, you can also customize the generator to generate names with a specific meaning or origin.

5. Are there any ethical concerns regarding using a random name generator?

There are no significant ethical concerns in using a random name generator as long as the data used is ethically sourced, and the generated names are not offensive or discriminatory. However, if the generator is used for commercial purposes, it is essential to ensure that the generated names do not violate any trademark or copyright laws.

Similar threads

  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
1
Views
642
  • Programming and Computer Science
Replies
8
Views
360
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
4
Views
392
  • Programming and Computer Science
Replies
7
Views
1K
Back
Top