# A special random subset of uniformly distributed numbers is NOT uniformly distributed?

I asked the same question in the post: A special random subset of uniformly distributed numbers is still uniformly distributed?

Let me describe my question again. Assume that I have a value range [1,1000].

Goal: I want to have 10 numbers randomly sampled from [1,1000].

case1:

I sample 20 numbers, a1, ..., a20 from [1,1000].

Then I sample b1, ..., b10 from [a1, a2, ..., a20].

b1, ..., b10 are what I want.


case2:

I partition [1,1000] into 10 intervals,

I1=[1,100], I2=[101,200], ... I10=[901,1000].

Then I sample one number bi from Ii.

Eventually I still have 10 numbers b1, ..., b10.


Everyone said that the numbers in case2 are not uniformly distributed.

I also agree with that.

However, I used MATLAB to generate case1 and case2, and then I ran 2-sample kolmogorov smirnov test on case1 and case2.

Eventually, kolmogorov smirnov test told me that they are the same!! (always accept null hypothesis)

Can anyone explain this phenomenon?

My code is as follows for the reference.

clear all;
n=1000;

case1=randsample(n,10);
case1=sort(case1);

case2=[];
for in=1:10
case2=[case2 randi( [((in-1)*100)+1 in*100]  ,1,1 ) ];
end

kstest2(case1,case2)

-
Typically, null hypothesis is rejected only when there is strong evidence it is false. Small samples seldom lead to rejection of null hypothesis. –  André Nicolas May 19 '13 at 19:11
You're hiding the non-randomness under a layer of randomness; hence it takes a large sample to discover it. Sample Case 1 at random in [0,9] and make Case 2 cycle through [0,9]. This will strip away the extra layer, and KS will give you a better answer. –  vadim123 May 19 '13 at 19:23
@vadim123 I don't get what you mean. Do you mean that for case 1, I sample just a number from [0,9]. And then, for case 2, how should I do? –  user4478 May 19 '13 at 19:34
@user4478 Case 2 loops through 0,9 just as you have now (only without the extra 2 digits). –  vadim123 May 19 '13 at 19:52