1

I have the following piece of code :

int numberofTimesToRandomize = 10;
long seed = System.nanoTime();
Random r = new Random(seed);
List<List<Integer>> listOfRandoms = new ArrayList<List<Integer>>();
List<Integer> l = service.get();
for (int i = 0; i < numberofTimesToRandomize; i++) {
    Collections.shuffle(l, r);
    List<Integer> rnd = l.subList(1, 100);
    listOfRandoms.add(rnd);
}

What I want to know is whether there is a way to determine the measure of randomness across the 10 lists each of size 100. The size of the list from which the random lists are picked is roughly 10000.

I have seen a couple of questions being answered with "no, there is no way". But those are for sequence of random numbers. A Good and SIMPLE Measure of Randomness

Any help would be appreciated.

EDIT : Based on Peter Lawreys question as to the purpose of this test, I thought one simple measure is to check if the resultant 10 lists are exactly the same independent of order. this question answers that for me : Simple way to find if two different lists contain exactly the same elements?

I wonder if this is the only way to unit test the above code.

Community
  • 1
  • 1
Krish Srinivasan
  • 568
  • 1
  • 6
  • 14
  • 4
    You do realize that "numberOfTimesToRandomize" is a ridiculous idea, right? If you shuffle a deck of cards (or a Collection) twice, it doesn't make it twice as random. – Kayaman Jan 17 '14 at 16:01
  • 1
    A random sequence has an equals chance of being 1, 2, 3, 4, 5 as any other sequence. What is the reason you want this test? – Peter Lawrey Jan 17 '14 at 16:01
  • 1
    Quoting the first answer to the question you linked to "I think what you need to do is identify the aspects of randomness that are important to you- distribution, distribution of digits, lack of common factors, expected number of primes, fibonacci and other "special" numbers etc. " – Peter Lawrey Jan 17 '14 at 16:02
  • @Kayaman - I am not sure I follow you. What I am intending through the variable numberOfTimesToRandomize is that I would like to generate a List of "numberOfTimesToRandomize" lists each of which are random. – Krish Srinivasan Jan 17 '14 at 16:11
  • @Lawrey - one purpose is as a unit test to make sure that the lists are at least random. In other words I am not producing the same list every time. Perhaps thats a good measure. If the lists are not the same then there is some randomness. – Krish Srinivasan Jan 17 '14 at 16:13
  • 1
    You need to copy `rnd` before adding it to `listOfRandoms`, or else you're going to get `numberOfTimesToRandomize` references to exactly the same list with exactly the same elements. – Louis Wasserman Jan 17 '14 at 17:17
  • @Wasserman - turns out that in my testing the result is as you predicted. However, I am not sure I understand why. List rnd is a new reference every time and l.subList should return a different slice of the List every time every time. – Krish Srinivasan Jan 17 '14 at 19:33

0 Answers0