Random Name Generator

How should I properly initialize char variables?
My code:

String randomPlanetName(){
  String name = "";
  int dimension = int(random(3,12));
  
  int repetitions = 0;
  boolean lastType;
  for(int i = 0;i == dimension;i++){
    boolean type = boolean(int(random(0,1)));
    char selection;
    if(repetitions < 2){
      type = !type;
    }
    if(type == true){
      if(i == 0){
        selection = upperCaseVowels[int(random(0,upperCaseVowels.length - 1))];
      }else{
        selection = lowerCaseVowels[int(random(0,lowerCaseVowels.length - 1))];
      }
    }
    if(type == false){
      if(i == 0){
        selection = upperCaseConsonants[int(random(0,upperCaseConsonants.length - 1))];
      }else{
        selection = lowerCaseConsonants[int(random(0,lowerCaseConsonants.length - 1))];
      }
    }
    name += selection;
    lastType = type;
    if(lastType == type){
      repetitions++;
    }else{
      repetitions = 0;
    }
  }
  return name;
}

Error: The local variable "selection" may not have been initialized

Thanks for reading, and thanks for answering!

if(type == true){ -> if (type) {

if(type == false){ -> else {

1 Like

Thanks! It worked! :smiling_face_with_three_hearts:

I’m suspicious that variable type won’t ever be assigned true outta that expression. :thinking:

You can do something like this instead: :bulb:
final boolean type = random(2) < 1;

1 Like

Yeah, I also noticed that this function never work…

boolean type = round(random(0,2)) == 1;

this is probably always false

1 Like

No, it’s random true or false
(Oops, looks like I put the wrong code into it)

1 Like

It don’t work even after changing the code…
Logic Error.

or

type=false; 
if(random(1)<0.5) 
     type=true;
1 Like

No, I don’t mean the random boolean, I mean the code.

void setup(){
  
}

void draw(){
  println(randomPlanetName());
}

char[] upperCaseVowels = {
  'A',
  'E',
  'I',
  'O',
  'U',
};

char[] lowerCaseVowels = {
  'a',
  'e',
  'i',
  'o',
  'u',
};

char[] upperCaseConsonants = {
  'B',
  'C',
  'D',
  'F',
  'G',
  'H',
  'J',
  'K',
  'L',
  'M',
  'N',
  'P',
  'Q',
  'R',
  'S',
  'T',
  'V',
  'W',
  'X',
  'Y',
  'Z',
};

char[] lowerCaseConsonants = {
  'b',
  'c',
  'd',
  'f',
  'g',
  'h',
  'j',
  'k',
  'l',
  'm',
  'n',
  'p',
  'q',
  'r',
  's',
  't',
  'v',
  'w',
  'x',
  'y',
  'z',
};

char[] numbers = {
  '0',
  '1',
  '2',
  '3',
  '4',
  '5',
  '6',
  '7',
  '8',
  '9',
};

char seperator = ' ';

String randomPlanetName(){
  String name = "";
  int dimension = int(random(3,12));
  
  int repetitions = 0;
  boolean lastType;
  for(int i = 0;i == dimension;i++){
    boolean type = round(random(0,2)) == 1;
    char selection;
    if(repetitions > 2){
      type = !type;
    }
    if(type){
      if(i == 0){
        selection = upperCaseVowels[int(random(0,upperCaseVowels.length))];
      }else{
        selection = lowerCaseVowels[int(random(0,lowerCaseVowels.length))];
      }
    }else{
      if(i == 0){
        selection = upperCaseConsonants[int(random(0,upperCaseConsonants.length))];
      }else{
        selection = lowerCaseConsonants[int(random(0,lowerCaseConsonants.length))];
      }
    }
    name += selection;
    lastType = type;
    if(lastType == type){
      repetitions++;
    }else{
      repetitions = 0;
    }
  }
  return name;
}

The name returned will always be "".

for (int i = 0; i < dimension; i++) {

1 Like

An alternative (and very interesting) way to shift upper to lower case (and vice-versa) ASCII letters: :nerd_face:

char letter = 'E';
println(letter); // E

char lower = (char) (letter | ' '); // e
println(lower);

char upper = (char) (lower & ~' '); // E
println(upper);

exit();
1 Like

OOOOH, It worked!!! THANKS! :heartpulse: :heartpulse: :heartpulse: :heartpulse: :heartpulse:

1 Like

Wait, my “avoid vowel consonant repetition” code don’t work.

Some of the names:

Dboan
Nxmranihgoe
Ndagwikehjm
Mkaliraymae
Otise
Aul
Ejt
Wbyde
Igohowui
Dboeauj
Jpxvaivhq
Trlaiby
Qqxruu
Nihfeznxeeo
Rmulyu
Zioeyoduxmt
Uaboxze
Iaw
Ioufa
Qtrda
Upahpo
Xuoowisdxue
Zztuiica
Akueuhefaoi
Ogw
Fasakjf
Udibzx
Ojyoooyohi
Vau
Lni
Luamg
Ebacu
Vjvuqi
Jjxdtyrubj
Oeoicicop
Eenva
Ahbqamu
Tkkeckzusyu
Vedkaqai
Gheao
Buusase
Ahobtu
Txupeiiaaih
Ucasjje
Hgtlymwi
Hzado
Ufju
Qfwgomsy
Ueteaq
Vao
Apyu
Flxe
Etuoo
Piiqzaovdgo
Ewtvkja
Hbsobiepr
Aguinuol
Knaoqo
Kueu
Wnguobize
Tixr
Euefu
Muerxeeok
Ofaa
Duoee
Ilwurjlj
Iotidhtwooz
Alarha
Feovnbtnoma
Ndcqxkuolx
Zqpmh
Shrqapie
Tnaezfoy
Rptqt
Duevgv
Wcpxcuo
Ayu
Huaooo
Egueyqp
Nileor
Aahiauowaqa
Syioebuov
Anu
Foaeqf
Uli
Yeiihhiyv
Iipfcii
Zuogonaoau
Ohkltyo
Arnnpeea
Aficiiaoin
Vgzisp
Eoeuue
Xei
Uecflvic
Cipie
Vaoziiraao
Vpnlwie
Ismumeaou
Iiippeiu
Cjgd
Siguka
Pmvoxwqozi
Uuageqrun
Bfuoe
Odjgdorvit
Uat
Ivnwooumcec
Aaied
Ezim
Nftffpz
Aifigwe
Bkoohujhkc
Wmwueee
Mzogpio
Ekearvie
Oio
Xgoocvii
Chnhvre
Zmtieoxm
Wqlqlew
Eqyefaxi
Qffurcdg

“avoid vowel consonant repetition”

Can you please explain

1 Like

Alright.

String randomPlanetName(){
  String name = "";
  int dimension = int(random(3,12));
  
  int repetitions = 0;////////////////////////////////////////////////////////////// variable for repetition count
  boolean lastType;
  for(int i = 0;i < dimension;i++){
    boolean type = round(random(0,2)) == 1;
    char selection;
    if(repetitions > 2){
      type = !type;///////////////////////////////////////////////////////////////// if repetitions is more than two, reverse the vowel consonant
    }
    if(type){
      if(i == 0){
        selection = upperCaseVowels[int(random(0,upperCaseVowels.length))];
      }else{
        selection = lowerCaseVowels[int(random(0,lowerCaseVowels.length))];
      }
    }else{
      if(i == 0){
        selection = upperCaseConsonants[int(random(0,upperCaseConsonants.length))];
      }else{
        selection = lowerCaseConsonants[int(random(0,lowerCaseConsonants.length))];
      }
    }
    name += selection;
    lastType = type;//////////////////////////////////////////////////////////////// for easiness we use type to say vowel or consonant
    if(lastType == type){
      repetitions++;//////////////////////////////////////////////////////////////// if the last type is equal to this type
    }else{////////////////////////////////////////////////////////////////////////// then change repetition count by 1
      repetitions = 0;////////////////////////////////////////////////////////////// or else set it to 0
    }
  }
  return name;
}

For example, I want to have a name like “Chareturn” and not “Fleaiiiiiaoster”.

(http://letsmakeagame.net/planet-name-generator/)

A funny name I generated from my generator: “Ieeoiiaea”

so you mean : avoid the repetition of a vowel OR a consonant

so earth, Saturn and moon not allowed

1 Like