Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class MakeBigArrayPerm
- {
- public static void main(String[] args) throws IOException
- {
- Random r = new Random();
- final int ARRAY_SIZE = 20;
- int [] nums1 = new int [ARRAY_SIZE];
- int [] nums2 = new int [ARRAY_SIZE];
- File outFile = new File ("output.txt");
- FileWriter fw = new FileWriter (outFile);
- PrintWriter pw = new PrintWriter (fw);
- //fill
- for(int i = 0; i < ARRAY_SIZE; i++)
- {
- nums1[i] = r.nextInt(9999999);
- pw.print(nums1[i] + ", ");
- }
- pw.println();
- //copy
- for(int i = 0; i < ARRAY_SIZE; i++)
- {
- nums2[i] = nums1[i];
- }
- //shuffle
- for (int i = 0; i < ARRAY_SIZE; i++)
- {
- int rIdx = r.nextInt(ARRAY_SIZE);
- int temp = nums2[i];
- nums2[i] = nums2[rIdx];
- nums2[rIdx] = temp;
- }
- for(int i = 0; i < ARRAY_SIZE; i++)
- {
- pw.print(nums2[i] + ", ");
- }
- pw.close();
- }
- }
Add Comment
Please, Sign In to add comment