Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Any explanation help please

I'm analyzing this code but find it hard to understand the random section. Whats the purpose of this?

[code=java]public class MyClass {
public static void main(String args[]) {
String[] wordList = {"Walking", "Running", "Riding-a-bike", "Eating", "Sleeping"};
String[] wordList2 = {"I-am", "You-are", "we-are", "I'm-not", "You-can't"};
String[] wordList3 = {"House", "Work", "Theater", "Ship", "Beach"};

          int arr1Length = wordList.length;
          int arr2Length = wordList2.length;
          int arr3Length = wordList3.length;

          //dont understand this section of code
          int rand1 = (int) (Math.random() * arr1Length);
          int rand2 = (int) (Math.random() * arr2Length); 
          int rand3 = (int) (Math.random() * arr3Length);

          String phrase = wordList[rand1] + " " + wordList2[rand2] + " " + wordList3[rand3];



Sign In or Register to comment.