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.
 

FAQ: I want to make a Nepali Random Name Generator

How does a Nepali Random Name Generator work?

A Nepali Random Name Generator works by combining different Nepali words or syllables to create unique names. These names can be generated randomly or based on specific criteria such as gender, meaning, or origin.

Can I customize the output of a Nepali Random Name Generator?

Yes, you can customize the output of a Nepali Random Name Generator by specifying parameters such as name length, starting letter, or including specific words or syllables. This allows you to tailor the generated names to suit your preferences.

Are the names generated by a Nepali Random Name Generator authentic?

The names generated by a Nepali Random Name Generator may not always be authentic Nepali names, as they are created by combining existing words or syllables. However, the generator can provide inspiration for unique and culturally appropriate names.

How can I use a Nepali Random Name Generator?

To use a Nepali Random Name Generator, simply input your desired parameters or criteria, such as gender or meaning, and click the generate button. The generator will then create a list of random names that meet your specifications.

Are Nepali Random Name Generators accurate?

Nepali Random Name Generators are not always accurate in terms of providing authentic or traditional Nepali names. However, they can be a fun and creative tool for generating unique and culturally inspired names for various purposes.

Similar threads

Replies
10
Views
2K
Replies
6
Views
1K
Replies
15
Views
2K
Replies
13
Views
1K
Replies
4
Views
1K
Back
Top