public class TestRandom { public static void main(String[] args){ Random random = new Random(441287210); for(int i=0;i<10;i++) System.out.print(random.nextInt(10)+" "); System.out.println(""); Random random2 = new Random(-6732303926L); for(int i=0;i<10;i++) System.out.print(random2.nextInt(10)+" "); System.out.println(""); System.out.println(randomString(-229985452)+' '+randomString(-147909649)); } public static String randomString(int seed) { Random rand = new Random(seed); StringBuilder sb = new StringBuilder(); for(int i=0;;i++) { int n = rand.nextInt(27); if (n == 0) break; sb.append((char) ('`' + n)); } return sb.toString(); }}
输出:
1 1 1 1 1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 hello world