Java List Random Item newRandomV1(int size, int price, List oldRandomList)

Here you can find the source of newRandomV1(int size, int price, List oldRandomList)

Description

new Random V

License

Apache License

Declaration

public static String newRandomV1(int size, int price, List<String> oldRandomList) 

Method Source Code


//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("]", "");
    }
}

Related

  1. makeListOfIntegersInRange(Integer size, Integer maxOfRange)
  2. makeRandomList(int arraySize, boolean unique)
  3. newRandom(int size, int price, List oldRandomList)
  4. newRandomIntegerList(int size)
  5. newRandomStringList(int size, String... strings)
  6. nextElement(List list)
  7. nextRandomElement(final List list)
  8. pickNAtRandom(List vals, int n, long seed)
  9. pickOneAtRandom(List list)