Advertisement
cd62131

FixedRandom.java

Sep 5th, 2017
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.68 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. public class FixedRandom {
  7.     public static void main(String[] args) {
  8.         long seed = 2017L;
  9.  
  10.         List<Integer> xs = new Random(seed).ints(20, 0, 19).collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
  11.         System.out.println(xs);
  12.  
  13.         Random r = new Random(seed);
  14.         List<Integer> ys = new ArrayList<>();
  15.         for (int i = 0; i < 20; ++i) {
  16.             ys.add(r.nextInt(19));
  17.         }
  18.         System.out.println(ys);
  19.  
  20.         Random r2 = new Random(seed);
  21.         int[] zs = new int[20];
  22.         for (int i = 0; i < zs.length; ++i) {
  23.             zs[i] = r2.nextInt(19);
  24.         }
  25.         System.out.println(Arrays.toString(zs));
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement