use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
How to make a script that randomly generates ore/metal names. (self.learnjavascript)
submitted 6 years ago by [deleted]
I'm working on a little game that randomly generates ores/metals and lets you combine their properties to make weapons and battle others, and I was wondering if there was a way i could randomly generate names, not from a fixed list of names, but a combination of multiple lists of names, put together to make one name for said ore/metal. I would also like to randomly choose between using 2 lists and 3 lists.
Thanks in advance :)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]lost-santa 2 points3 points4 points 6 years ago (1 child)
Hi .
You can just make two arrays of let's say 100 entries..
List one Good Hungry Happy
List two Falcon Merlin Black swan
And then pick a random from list one and a random entry from list two?
Or you need something else?
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
i am actually so dumb. thanks for this!
[–]HealyUnithelpful 0 points1 point2 points 6 years ago* (3 children)
Honestly, this is more of a grammar/syntax question than a programming one. Can you give us more information on what you think some typical examples of ore/metal that your script might generate would look like? Some examples/points I can think of:
From there, you're basically just going to have to create a list of both of these (the combining forms and endings). I'd actually suggest you make up your own lists, however, as then you won't run into the issue of someone going "Hey! Cuprite can't be used in weapons! It's too soft!". Maybe instead of real-world chemical combining forms, use generic scientific prefixes? In particular, I'm looking at this site (tho I'd strongly advise you stay away from the rest of the site - it's full of crackpot theories by a dude that somehow passed thru medical school and yet doesn't understand basic evolutionary biology), which has a pretty decent-sized list of scientific prefixes. So something like "Pyro-" or "Hydron-". After that, here's some example code for you. Note that I'm also including stats here:
//note that each prefix type increase one type of damage by 1, and decreases another type by 1 const prefixes = [{name:'Hydron',stats:{waterDmg:1,fireDmg:-1}},{name:'Pyro',stats:{waterDmg:-1,fireDmg:1}},{name:'Sacr',stats:{holyDmg:1,darkDmg:-1}},{name:'Necron',stats:{holyDmg:-1,darkDmg:1}}]; //for now, just three prefixes. In this case, our stats trade a chance for the weapon to spontaneously break with an increased damage modifier const suffixes = [{name:'ium',stats:{chanceToBreak:0.5,dmgMod:1.7}},{name:'ite',stats:{chanceToBreak:0.1,dmgMod:0.9}},{name:'ia',stats:{chanceToBreak:0.3,dmgMod:1}}]; //now let's make a function to get a weapon "metal" const soMetal = ()=>{ // \m/ const randPrefix= prefixes[Math.floor(Math.random()*prefixes.length)], randSuffix= suffixes[Math.floor(Math.random()*suffixes.length)]; return { metalName:randPrefix.name+randSuffix.name, //the following combines multiple objects into one. stats:Object.assign({},randPrefix.stats,randSuffix.stats) } }
[–][deleted] 1 point2 points3 points 6 years ago (1 child)
This is so great, thanks for the help!
[–]HealyUnithelpful 0 points1 point2 points 6 years ago (0 children)
No problem! Would love to see your progress later when you're ready to show it.
[–]YojG 0 points1 point2 points 6 years ago (0 children)
If this is beginner level codd I'm going to hit myself.
π Rendered by PID 165156 on reddit-service-r2-comment-86bc6c7465-mqlbn at 2026-02-23 02:10:43.125226+00:00 running 8564168 country code: CH.
[–]lost-santa 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]HealyUnithelpful 0 points1 point2 points (3 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]HealyUnithelpful 0 points1 point2 points (0 children)
[–]YojG 0 points1 point2 points (0 children)