[Solved] Why Random random = new Random()? [closed]


Just a note, the first commenter is correct, you probably could have found this through a bit of Googling, but here’s the answer as best as I can explain it:

Let’s take that code:

Random random = new Random();

The first random just says what type of data the variable is going to store – in this case, “Random.” The second random is the name of the variable. You can call this almost anything you want, “random,” “ran,” even something completely unrelated like “ThisIsAVar.” Then you set the new variable (using the “=”) to a new Random type.

A more generic example would be (as “Random” in the last explanation messes with the grammar):

string NewString = new String("Hello there!");

You’re creating a new variable called NewString with type of string, and setting that to a new String type with the parameter “Hello there!”

solved Why Random random = new Random()? [closed]