0 votes
1 view
in Java by (4.1k 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 (46.1k 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
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...