Cody

# Problem 44435. Testing for randomness: uniform distribution of real numbers (distribution checking)

Solution 1405607

Submitted on 5 Jan 2018 by Thomas Steffen
• Size: 37
• This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
% Random, short faults = 0; isRandom_C = true; for i = 1 : 10 x = 1000 * rand(1, 20+randi(10)); isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.9834 0.9834 1.0000 y = logical 1 c = 1.0000 0.9760 0.9760 1.0000 y = logical 1 c = 1.0000 0.9750 0.9750 1.0000 y = logical 1 c = 1.0000 0.9827 0.9827 1.0000 y = logical 1 c = 1.0000 0.9824 0.9824 1.0000 y = logical 1 c = 1.0000 0.9872 0.9872 1.0000 y = logical 1 c = 1.0000 0.9883 0.9883 1.0000 y = logical 1 c = 1.0000 0.9949 0.9949 1.0000 y = logical 1 c = 1.0000 0.9940 0.9940 1.0000 y = logical 1 c = 1.0000 0.9945 0.9945 1.0000 y = logical 1

2   Pass
% Bimodal, short faults = 0; isRandom_C = false; for i = 1 : 10 x = [rand(1, 10+randi(5)), 999 + rand(1, 10+randi(5))]; isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.8566 0.8566 1.0000 y = logical 0 c = 1.0000 0.8607 0.8607 1.0000 y = logical 0 c = 1.0000 0.8643 0.8643 1.0000 y = logical 0 c = 1.0000 0.8608 0.8608 1.0000 y = logical 0 c = 1.0000 0.8615 0.8615 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8607 0.8607 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8672 0.8672 1.0000 y = logical 0 c = 1.0000 0.8670 0.8670 1.0000 y = logical 0

3   Pass
% Random, medium faults = 0; isRandom_C = true; for i = 1 : 10 x = randi(1000) + 1000 * rand(1, 100+randi(10)); isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.9988 0.9988 1.0000 y = logical 1 c = 1.0000 0.9976 0.9976 1.0000 y = logical 1 c = 1.0000 0.9929 0.9929 1.0000 y = logical 1 c = 1.0000 0.9980 0.9980 1.0000 y = logical 1 c = 1.0000 0.9959 0.9959 1.0000 y = logical 1 c = 1.0000 0.9966 0.9966 1.0000 y = logical 1 c = 1.0000 0.9962 0.9962 1.0000 y = logical 1 c = 1.0000 0.9967 0.9967 1.0000 y = logical 1 c = 1.0000 0.9944 0.9944 1.0000 y = logical 1 c = 1.0000 0.9934 0.9934 1.0000 y = logical 1

4   Pass
% Bimodal, medium faults = 0; isRandom_C = false; for i = 1 : 10 x = randi(1000) + [rand(1, 50+randi(5)), 999 + rand(1, 50+randi(5))]; isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.8660 0.8660 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8660 0.8660 1.0000 y = logical 0 c = 1.0000 0.8664 0.8664 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8657 0.8657 1.0000 y = logical 0 c = 1.0000 0.8662 0.8662 1.0000 y = logical 0 c = 1.0000 0.8662 0.8662 1.0000 y = logical 0

5   Pass
% Skewed, medium faults = 0; isRandom_C = false; for i = 1 : 10 x = 10 ./ rand(1, 100+randi(10)); isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.5423 0.5423 1.0000 y = logical 0 c = 1.0000 0.2718 0.2718 1.0000 y = logical 0 c = 1.0000 0.3476 0.3476 1.0000 y = logical 0 c = 1.0000 0.4419 0.4419 1.0000 y = logical 0 c = 1.0000 0.3271 0.3271 1.0000 y = logical 0 c = 1.0000 0.4509 0.4509 1.0000 y = logical 0 c = 1.0000 0.4278 0.4278 1.0000 y = logical 0 c = 1.0000 0.3651 0.3651 1.0000 y = logical 0 c = 1.0000 0.5289 0.5289 1.0000 y = logical 0 c = 1.0000 0.6621 0.6621 1.0000 y = logical 0

6   Pass
% Random, long faults = 0; isRandom_C = true; for i = 1 : 10 x = 1000 * rand(1, 500+randi(10)); isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.9992 0.9992 1.0000 y = logical 1 c = 1.0000 0.9996 0.9996 1.0000 y = logical 1 c = 1.0000 0.9994 0.9994 1.0000 y = logical 1 c = 1.0000 0.9990 0.9990 1.0000 y = logical 1 c = 1.0000 0.9993 0.9993 1.0000 y = logical 1 c = 1.0000 0.9996 0.9996 1.0000 y = logical 1 c = 1.0000 0.9977 0.9977 1.0000 y = logical 1 c = 1.0000 0.9988 0.9988 1.0000 y = logical 1 c = 1.0000 0.9980 0.9980 1.0000 y = logical 1 c = 1.0000 0.9990 0.9990 1.0000 y = logical 1

7   Pass
% Skewed (1), long faults = 0; isRandom_C = false; for i = 1 : 10 x = 10 ./ rand(1, 500+randi(5)) - randi(1000); isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.1060 0.1060 1.0000 y = logical 0 c = 1.0000 0.3910 0.3910 1.0000 y = logical 0 c = 1.0000 0.4046 0.4046 1.0000 y = logical 0 c = 1.0000 0.4360 0.4360 1.0000 y = logical 0 c = 1.0000 0.3105 0.3105 1.0000 y = logical 0 c = 1.0000 0.1034 0.1034 1.0000 y = logical 0 c = 1.0000 0.3413 0.3413 1.0000 y = logical 0 c = 1.0000 0.2340 0.2340 1.0000 y = logical 0 c = 1.0000 0.3376 0.3376 1.0000 y = logical 0 c = 1.0000 0.1184 0.1184 1.0000 y = logical 0

8   Pass
% Skewed (2), long faults = 0; isRandom_C = false; for i = 1 : 10 x = randi(1000) - 10 ./ rand(1, 500+randi(5)); isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.1781 0.1781 1.0000 y = logical 0 c = 1.0000 0.2078 0.2078 1.0000 y = logical 0 c = 1.0000 0.2559 0.2559 1.0000 y = logical 0 c = 1.0000 0.2614 0.2614 1.0000 y = logical 0 c = 1.0000 0.3044 0.3044 1.0000 y = logical 0 c = 1.0000 0.1166 0.1166 1.0000 y = logical 0 c = 1.0000 0.2232 0.2232 1.0000 y = logical 0 c = 1.0000 0.1165 0.1165 1.0000 y = logical 0 c = 1.0000 0.1184 0.1184 1.0000 y = logical 0 c = 1.0000 0.1416 0.1416 1.0000 y = logical 0

9   Pass
% Bimodal, long faults = 0; isRandom_C = false; for i = 1 : 10 x = [rand(1, 250+randi(5)), 999 + rand(1, 250+randi(5))]; isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0 c = 1.0000 0.8663 0.8663 1.0000 y = logical 0

10   Pass
% 'Normal' (a.k.a. 'Gaussian'), long faults = 0; isRandom_C = false; for i = 1 : 10 x = 250 * randn(1, 500+randi(5)); isRandom = isItRandom(x); if ~isequal(isRandom, isRandom_C), faults = faults + 1; warning('*** CAUTION: %u faults recorded so far. ***', faults); end; assert(faults <= 2, 'Too many wrong assessments.'); end;

c = 1.0000 0.9846 0.9846 1.0000 y = logical 0 c = 1.0000 0.9685 0.9685 1.0000 y = logical 0 c = 1.0000 0.9672 0.9672 1.0000 y = logical 0 c = 1.0000 0.9734 0.9734 1.0000 y = logical 0 c = 1.0000 0.9832 0.9832 1.0000 y = logical 0 c = 1.0000 0.9751 0.9751 1.0000 y = logical 0 c = 1.0000 0.9796 0.9796 1.0000 y = logical 0 c = 1.0000 0.9755 0.9755 1.0000 y = logical 0 c = 1.0000 0.9788 0.9788 1.0000 y = logical 0 c = 1.0000 0.9810 0.9810 1.0000 y = logical 0