How do I make code dependent on the results of a random string generation?

edited October 2013 in How To...

I'm trying to code a random generator (something like http://www.seventhsanctum.com/generate.php?Genname=charscramble), and I'm trying to make a second "dice roll" dependent on the first one. For example, if the first random generation gets the result "Bird," the program should then select the next result from the list "Woodpecker", "Jay", "Eagle", etc etc, but if the first random generation gets the result "Canine," the program should select the next result from the list "Dog", "Wolf", "Coyote", etc etc. But, being a Processing novice, I'm not sure how to do that.

Comments

  • There are several ways to do this, it depends how you make your lists, for example.

    You can do a two dimensions array, one dimension having the kind of beast, the other dimension having the species..

    String[] kinds =
    {
      "Bird", "Dog"
    };
    String[][] beasts =
    {
      { "Woodpecker", "Jay", "Eagle" },
      { "Dog", "Wolf", "Coyote" },
    };
    
    for (int i = 0; i < 5; i++)
    {
      int kind = int(random(kinds.length));
      println(kinds[kind]);
      int beast = int(random(beasts[kind].length));
      println(beasts[kind][beast]);
      println();
    }
    
Sign In or Register to comment.