Here is an algorithm problem that I am trying to solve(It's written in Korean.): https://www.acmicpc.net/problem/10944
If I simply translate the problem, I need to generate a number between 1 and 10,000. The resulting number must be the same as the random number which is generated by the server(a referee)
Is this possible? Can I guess what the system server would generate and Can I match it with my program's result?
I figured out that there are two kinds of way to make a random number in Java.
- Random
- Math.random()
And I can manipulate(or predefine) the result with Random. And I just think it might be possible to solve the problem.
For example:
import java.io.IOException;
import java.util.Random;
public class Solution {
public static void main(String[] args) throws IOException {
Random rnd = new Random(1);
System.out.println(rnd.nextInt(10000));
rnd = new Random(1);
System.out.println(rnd.nextInt(10000));
}
}
It shows the same result because the parameter of Random is the same. And I tried with Random. But I couldn't solve that problem.
Like this:
import java.io.IOException;
import java.util.Random;
public class Solution {
public static void main(String[] args) throws IOException {
Random rnd = new Random(1);
System.out.println(rnd.nextInt(10000));
}
}
And as I remember, Math.random() is generated by system time. But I can't find any information for that. If that's true and it may be possible to solve the problem. Because I can program with the system time and the result will always correspond.