# Random Name Generator

**URL:** https://discourse.processing.org/t/random-name-generator/25008
**Category:** Beginners
**Created:** [October 29, 2020, 10:16am UTC](https://discourse.processing.org/t/random-name-generator/25008 "2020-10-29T10:16:49Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 29, 2020, 10:16am UTC](https://discourse.processing.org/t/random-name-generator/25008/1 "2020-10-29T10:16:49Z")

</div>

How should I properly initialize `char` variables?  
My code:

```auto
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!

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [October 29, 2020, 10:34am UTC](https://discourse.processing.org/t/random-name-generator/25008/2 "2020-10-29T10:34:58Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 29, 2020, 10:40am UTC](https://discourse.processing.org/t/random-name-generator/25008/3 "2020-10-29T10:40:13Z")

</div>

Thanks! It worked! 🥰

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [October 29, 2020, 10:43am UTC](https://discourse.processing.org/t/random-name-generator/25008/4 "2020-10-29T10:43:58Z")

</div>

> [@HumanoidX](#):
>
> `boolean type = boolean(int(random(0,1)));`

I’m suspicious that variable _type_ won’t ever be assigned `true` outta that expression. 🤔

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

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 29, 2020, 10:52am UTC](https://discourse.processing.org/t/random-name-generator/25008/5 "2020-10-29T10:52:19Z")

</div>

Yeah, I also noticed that this function never work…

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 29, 2020, 10:52am UTC](https://discourse.processing.org/t/random-name-generator/25008/6 "2020-10-29T10:52:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 29, 2020, 10:59am UTC](https://discourse.processing.org/t/random-name-generator/25008/7 "2020-10-29T10:59:06Z")

</div>

this is probably always false

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 29, 2020, 11:01am UTC](https://discourse.processing.org/t/random-name-generator/25008/8 "2020-10-29T11:01:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 29, 2020, 11:08am UTC](https://discourse.processing.org/t/random-name-generator/25008/9 "2020-10-29T11:08:50Z")

</div>

> [@HumanoidX](#):
>
> this function never work…

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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 29, 2020, 11:16am UTC](https://discourse.processing.org/t/random-name-generator/25008/10 "2020-10-29T11:16:19Z")

</div>

> [@GoToLoop](#):
>
> `final boolean type = random(2) < 1;`

or

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

```

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 29, 2020, 11:50am UTC](https://discourse.processing.org/t/random-name-generator/25008/11 "2020-10-29T11:50:27Z")

</div>

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

```auto
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 `""`.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 29, 2020, 12:12pm UTC](https://discourse.processing.org/t/random-name-generator/25008/12 "2020-10-29T12:12:48Z")

</div>

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

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [October 29, 2020, 12:17pm UTC](https://discourse.processing.org/t/random-name-generator/25008/13 "2020-10-29T12:17:53Z")

</div>

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

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

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

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

exit();

```

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 30, 2020, 12:10pm UTC](https://discourse.processing.org/t/random-name-generator/25008/14 "2020-10-30T12:10:36Z")

</div>

OOOOH, It worked!!! THANKS! 💗 💗 💗 💗 💗

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 30, 2020, 12:23pm UTC](https://discourse.processing.org/t/random-name-generator/25008/15 "2020-10-30T12:23:42Z")

</div>

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

Some of the names:

```auto
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
```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 30, 2020, 12:33pm UTC](https://discourse.processing.org/t/random-name-generator/25008/16 "2020-10-30T12:33:30Z")

</div>

> “avoid vowel consonant repetition”

Can you please explain

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 30, 2020, 12:42pm UTC](https://discourse.processing.org/t/random-name-generator/25008/17 "2020-10-30T12:42:52Z")

</div>

Alright.

```auto
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;
}

```

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 30, 2020, 12:45pm UTC](https://discourse.processing.org/t/random-name-generator/25008/18 "2020-10-30T12:45:10Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![HumanoidX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humanoidx/32/8506_2.png) [@HumanoidX](https://discourse.processing.org/u/HumanoidX)
#### Post date: [October 30, 2020, 12:48pm UTC](https://discourse.processing.org/t/random-name-generator/25008/19 "2020-10-30T12:48:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 30, 2020, 12:56pm UTC](https://discourse.processing.org/t/random-name-generator/25008/20 "2020-10-30T12:56:18Z")

</div>

> [@Chrisir](#):
>
> avoid vowel consonant repetition

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

so earth, Saturn and moon not allowed

[Next page](https://discourse.processing.org/t/random-name-generator/25008.md?page=2)
