日期:2014-05-20 浏览次数:20645 次
public static void main(String[] args) {
int n = 10000000, k = 1000000;
boolean[] appear = new boolean[n];
Random r = new Random();
int[] nums = new int[k];
for (int i = 0; i < k; i++) {
int j = -1;
while (appear[j = r.nextInt(n)]);
nums[i] = j;
//appear[j] = true;System.out.println(nums[i]);
}
}
package com;
import java.util.ArrayList;
import java.util.List;
public class B {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
List list=new ArrayList<Integer>();
for(int i=1;i<=10000000;i++){
list.add(i);
}
long start=System.currentTimeMillis();
java.util.Collections.shuffle(list);
System.out.println(System.currentTimeMillis()-start);
}
}
public static void main(String[] args) {
int n = 10000000, k = 1000000;
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = i;
Random r = new Random();
int[] nums = new int[k];
for (int i = 0; i < k; i++) {
int j = r.nextInt(n - i) + i;
nums[i] = arr[j];
arr[j] = arr[i];