Log In  


The code below creates a random "word" that's 2 to 12 characters long. Some results are better than others and absolutely no guarantee it won't generate rude words (in whatever language you'd like to be offended in). This snippet might come in handy somewhere and can very easily be tweaked.
Great for all your randomly generated NPC's, Legendary Weapons, Chthonic demons and faraway planet systems.

Very loosely based on Jabbalaci's Python version (https://github.com/jabbalaci/Elite) of Ian Bell's txtelite.c script for Elite.

str_namefrags=split("AB,OU,AA,IT,ION,YL,IF,ON,ETO,AE,ERA,US,EON,ES,AR,UME,IN,AH,ER,AL,UR,AV,ET,IUS,IE,UJ,EY,YS,ON","SE,NYA,HY,SU,LO,NU,GA,LON,TH,NA,HO,LE,XA,DIA,GE,ZA,VAN,CE,HE,BI,SO,MA,DI,VE,RE,SEN,RA,TE,HI,NY,WEN,DO,QU,KI")

function random_word()
  -- creates a random word
  -- words are anything from 2 to 12 characters long

  -- _len = length of the word in fragments
  local _len,_res,_hyphen,_c,_frag = 2+flr(rnd(3)),"",0,0,""

  for z=1,_len do

    _frag=str_namefrags[1+flr(rnd(#str_namefrags))]

    -- generate a random chance to do special stuff with the chosen fragment
    _c=flr(rnd(16))

    if _c==0 then
      -- switch the first and last letter
      _res=_res..sub(_frag,-1,-1)..sub(_frag,1,1)

    elseif (_c==1 and _res!="" and z<_len and _hyphen==0) then
      -- if the string already contains some text, we're not at the
      -- last fragment and we've not done
      -- this before: add either a space, hyphen or apostrophe.
      local _mark = 1+flr(rnd(3))
      _res=_res..sub(" '-",_mark,_mark)
      _hyphen=1

    elseif _c==2 then
      -- use only the first letter of the chosen fragment
      _res=_res..sub(_frag,1,1)

    elseif _c==3 then
      -- use only the last letter of the chosen fragment
      _res=_res..sub(_frag,-1,-1)

    else 
      -- in all other cases: simply add the chosen fragment
      _res=_res.._frag

    end
  end

  if (#_res<5 and flr(rnd(70))==0) then
    -- if the result is short and once in 70 times:
    -- add the result to itself with a space in between
    _res=_res.." ".._res	 

  end

  return _res

end

A sample of the "words" it will generate:
ETORAU
VEAUSSEN
NQU
IFVANERA
DIAIIUS
GESEUJAH
VANONA
TEUJAVUJ
CELOOUVE
INNUE
NYADIA
RAUSY
UJSU
REZA
SYIE
ONEY
ETUSEYR
IUSYL
ITSENHEDIA
OUQREZA
DOARAH
ELE
DI'AA
AVHISU
TIURQU
US-DIUS
LENUITWEN
AEOUTHA
UME UME
KIETNYA
EEAASU
REUMEEY
DIL
ITARNYALO
CEIFU
HE-ALSU
ABHIAA
AVALAAV
TELONHY

2


2

Cart #randoword-1 | 2022-01-25 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
2

Busy little program, @Miez. Here is one I did back on the Apple ][ when determining random names for items. Code might be a bit smaller.

  • Continent: vcvc
  • Town: cvvcvc
  • Dungeon: vcvvc
  • Monster: cvccvc
  • Weapon: cvcvvc

@dw817 - that's some neat little code! Very awesome. Mine can definitely be optimized but the solution you have with the patterns (that can of course also be randomly generated) is very nice. Might take some inspiration from that!


Glad to help, @Miez. :)

I remember years ago just learning GFA when someone posted a program to bounce text on the screen, and the source-code was over 100-lines long !

I said I think I can do it better. He said go for it. I did, and while today I could make it considerably smaller - at the time I rewrote it in 8-lines of code.

Sometimes we get so caught up in trying to reproduce someone else's pattern or formula we lose track of what it is we are accomplishing.

In this case I wanted something that could be pronounceable. So obviously you would never have anything with two consonants to begin with.

Oh you might get lucky and have CH or SH, but what if it's the reverse ? HC or HS which of course is an impossible word.

You'll also see I took out some letters like C, J, Q, and X. What with words like CITY and CAT, C takes on 2-different sounds and Q must always have a U after it.

J in itself does not make very good words if you have a CC in the middle somewhere, And X is always troublesome as it makes a KS or Z sound by itself.

So removing these also makes the Randoword easier to function and create more pronounceable words.

It's not perfect.

I know years ago I tried to improve on my Randoword by adding possibilities such as for instance words beginning with letter C such as

[CH]ASE [CL]EAR [CR]AFT

So, yeah it can get complex in a real hurry.



[Please log in to post a comment]