Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)

This Statement will print “hello world”. Could anyone explain this?

System.out.println(randomString(-229985453) + " " + randomString(-147909650));

And randomString() looks like this:

public static String randomString(int i)

{

   Random ran = new Random(i);

   StringBuilder sb = new StringBuilder();

   while (true)

   {

       int k = ran.nextInt(27);

       if (k == 0)

           break;

       sb.append((char)('`' + k));

   }

   return sb.toString();

}

1 Answer

0 votes
by (46k points)

Whenever we use JAVA java.util.RAndom with a definite seed parameter (Here, in your syntax -229985453 or -147909650), it follows the random number generation algorithm starting with a seed value.  

All Random numbers created with the same seed will generate an identical pattern of numbers every time.

To know more click here.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...