If this is your first visit, be sure to check out the FAQ by clicking the link above. You have to register before you can post.

If you have recently signed up, please make sure you log in so that your activity is registered. This is required for automatic promotions to work and to ensure your account is not deleted during the registration process.

if isVowel( temp[1] ) then
begin
// 1st is a vowel
if isVowel( temp[2] ) then
begin
// 2nd is a vowel = 3rd must be a consonant
if (temp[2] = input[1]) and (not isVowel(input[1])) then bufferstrings.Add(listbox1.Items[j])
end
else
begin
// 2nd is a consonant = 3rd must be a consonant or vowel
if (temp[2] = input[1]) then bufferstrings.Add(listbox1.Items[j]);
end;
end
else
begin
// 1st is a consonant
if isVowel( temp[2] ) then
begin
// 2nd is a vowel = 3rd must be a consonant or vowel
if (temp[2] = input[1]) then bufferstrings.Add(listbox1.Items[j])
end
else
begin
// 2nd is a consonant = 3rd must be a vowel
if (temp[2] = input[1]) and (isVowel(input[1])) then bufferstrings.Add(listbox1.Items[j]);
end;
end;

Re: Random name generation

Hi there, are you still working on this? I'm fairly new and catching up on all the posts here - it's a great resource and i've learned a lot already. Normally if an app does roughly what i want it to do then i'm happy

It's not a better way, but here's a method:
i created "rules" for which letters can follow other letters depending on whether they start, end or are in the middle of the word.
This is more random than your method (i couldn't figure out what you put in the memo), most of the words aren't english, but you could change the rules to compenste for this.

Psuedo code:

Code:

loop through names
loop through all words in name
loop through all letters in word
pick a random letter
if it's been used already pick another one
if they've all been tried then exit to name loop
if there's only 1 letter in the word then skip checks
check vowel/consonant order (to make it semi-pronouncable)
check if this is a valid letter according to the ruleset
if any of the checks fail then exit to name loop
end letter loop
end word loop
end name loop

type
{*------------------------------------------------------------------------------
record to hold character info and rules
code: ascii code for char
exs: character exclusion for beginning of word. character indexes are or'd together
and 1 shifted left
eg: a=0, b=1, c=2. the "exs" for this would be (1 shl 0)+(1 shl 1)+(1 shl 2)=7
exs of 0 = exclude all chars, 67108863 = allow all chars
i have written an app so i didn't have to re-calc these
exn: as above but for exclusion within a word
exf: as above but for characters ending the word
-------------------------------------------------------------------------------}
tmychar = record
code: byte;
exs,exn,exf : cardinal;
end;

{*------------------------------------------------------------------------------
character index
@param c is the character to check
@return the character index for a given char
-------------------------------------------------------------------------------}
function ci(c: char): byte;
begin
result:=ord(c)-cs;
end;

{*------------------------------------------------------------------------------
check if a character is a vowel
@param c is the character to check
@return true if it is, false if not
-------------------------------------------------------------------------------}
function isvowel(c: char): boolean;
begin
result:=ci(c) in vowels;
end;

{*------------------------------------------------------------------------------
check if the current character is valid
@param wrd is the word to be checked
@param len is the desired name length
@return true if it's valid, false if not
-------------------------------------------------------------------------------}
function valid(const wrd: string;const len: integer): boolean;
var
i : integer;
c1,c2: byte;

{*------------------------------------------------------------------------------
vowel/consonant order check
checks there aren't too many vowels/consonants in succession. three characters are
checked
@param c a true element checks for a vowel, false for consonant
@return true if it fits the v/c ruleset, false if not
-------------------------------------------------------------------------------}
function check(c: array of boolean): boolean;
var
k: integer;
begin
result:=true;
for k:=0 to 2 do
result:=result and (isvowel(wrd[i+k])=c[k]);
end;

{*------------------------------------------------------------------------------
get the parameter and convert it to a number
@param p is the parameter index
@param v is the return value
@param def is the default value to assign on error
@param l is the lower limit
@param h is the upper limit
-------------------------------------------------------------------------------}
procedure num(p: byte;out v: integer;const def,l,h: integer);
begin
if not str2int(paramstr(p),v) then v:=def
else v:=min(max(v,l),h);
end;

begin
if paramcount=0 then goto skip; // use defaults
i:=1;
while i<=paramcount do begin
s:=lowercase(paramstr(i));
if s[1]=swchar then begin
found:=false;
for o:=0 to high(switches) do
if copy(s,2,4)=string(switches[o]) then begin
if (i=paramcount) or (paramstr(i+1)[1]=swchar) then begin
if (copy(s,2,3)<>'dbg') and (copy(s,2,1)<>'?') then begin
writeln('no paramater for option: ',s);
halt;
end;
end;
if copy(s,2,3)='cfg' then loadcfg(paramstr(i+1))
else if copy(s,2,1)='?' then usage
else if copy(s,2,3)='dbg' then incomp:=True
else if copy(s,2,3)='rnd' then num(i+1,RandSeed,0,-maxint,MaxInt)
else if copy(s,2,3)='min' then num(i+1,minlen,defminlen,3,maxlen)
else if copy(s,2,3)='max' then num(i+1,maxlen,defmaxlen,minlen,20)
else if copy(s,2,3)='wrd' then num(i+1,wrdcount,defwrdcnt,1,10)
else if copy(s,2,3)='gen' then num(i+1,gencount,defgencnt,1,100);
found:=true;
break;
end;
if not found then begin
Writeln('unknown switch: ',s);
usage;
end;
end;
inc(i);
end;
skip:
if RandSeed=0 then Randomize;
if incomp then Writeln('Seed: ',RandSeed);
end;

Extract to a folder somewhererng.exe is the console app to generate the names.
run it from a command window and use /? for options

rngcodes.exe is the app to create/load/save the rulesets
pick a letter from the listbox choose which letters are allowed on the grid to the right. each letter has 3 sections for Starting, Ending & middle of the word. LMB selects & RMB clears