Randomly Generate a Name?

0 favourites
  • 9 posts
  • How do I randomly generate a name using C2?

  • Could you be more specific?

    Do you have a list of names you want to randomly pick one of?

    Would you like to generate the name from random syllables?

    Is "Q1hm5z&" an acceptable name?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It doesn't matter. I could probably modify the script for my purposes.

    I figure Q1hm5z& would be useful at some point in my programming travels.

  • The system expressions choose() and random() are probably what your looking for, you can find out more about them in the manual.

  • choose ("Adam", "Bernard", "Cecil", "Doark", "Effreim", "Figgy", "Hanook")

    etc.

  • Interesting. Can I pair the choose expression with an array? May I have an example?

    At the very least, I think I could vary the length of the name, by using random() and loops, correct?

  • Let's assume you have an array filled with the all the possible characters on it's X axis. In pseudo-code:

    Var Name = ""

    For Loop: from 1 to However many characters you want the name

        Add Array.at(floor(random(Array.Width))) to Name

    If it were me, I wouldn't use individual letters, I would set up a system that alternates between consonant groups (e.g. str,th,v,gh,s,wr,r,ph) and vowel groups (e.g. a,ou,ea,ay,oo,ai). It's more work, but yields more natural results.

  • I see, I suppose the best way to make names and then add them to another array would be add Var Name to an array?

  • You could do that. You could also generate the random names directly in an array.

    Let's assume you have 2 arrays:

    Characters - An array with all the possible characters of a name along its X axis.

    Names - A array you want to populate with random names along its X axis.

    For Each X Element in Names:

       Set value at Names.curx to ""

       For Loop: from 1 to However many characters you want the name

           Set value at Names.curx to Names.CurValue & Characters.at(floor(random(Characters.Width)))

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)