Here you can find the source of newRandomV1(int size, int price, List
public static String newRandomV1(int size, int price, List<String> oldRandomList)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; import java.util.Random; public class Main { public static String newRandomV1(int size, int price, List<String> oldRandomList) { long start = System.currentTimeMillis(); List<String> randomList = new ArrayList<String>(); int r = 10000000; for (int i = 1; i <= price; i++) { if (!oldRandomList.contains(String.valueOf(r + i))) { randomList.add(String.valueOf(r + i)); }/* w ww. j a va 2s .c o m*/ } long mmmm = System.currentTimeMillis(); long secs = (mmmm - start) / 1000; System.out.println(secs); List<String> ranList = new ArrayList<String>(); for (int j = 0; j < size; j++) { if (randomList.size() > 0) { int ran = new Random().nextInt(randomList.size()); ranList.add((String) randomList.get(ran)); randomList.remove(ran); } } return ranList.toString().replaceAll("\\s+", "").replace("[", "").replace("]", ""); } }