Cody

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

Solution 1945949

Submitted on 22 Sep 2019
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;

bins = 6 8 7 3 other = 1 len = 24 other = 1 binsiz = 4 bins = 10 12 5 3 other = 1 len = 30 other = 1 binsiz = 4 bins = 6 5 8 2 other = 1 len = 21 other = 1 binsiz = 4 bins = 8 4 9 5 other = 1 len = 26 other = 1 binsiz = 4 bins = 9 12 other = 1 len = 21 other = 1 binsiz = 2 y = logical 0 [Warning: *** CAUTION: 1 faults recorded so far. ***] [> In ScoringEngineTestPoint1 (line 9) In solutionTest (line 5)] bins = 5 13 6 3 other = 1 len = 27 other = 1 binsiz = 4 y = logical 0 [Warning: *** CAUTION: 2 faults recorded so far. ***] [> In ScoringEngineTestPoint1 (line 9) In solutionTest (line 5)] bins = 11 8 8 3 other = 1 len = 30 other = 1 binsiz = 4 bins = 5 8 10 3 other = 1 len = 26 other = 1 binsiz = 4 bins = 8 4 7 2 other = 1 len = 21 other = 1 binsiz = 4 bins = 9 10 9 2 other = 1 len = 30 other = 1 binsiz = 4

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;

bins = 14 11 other = 1 len = 25 other = 1 binsiz = 2 y = logical 0 bins = 12 12 other = 1 len = 24 other = 1 binsiz = 2 y = logical 0 y = logical 0 bins = 13 15 other = 1 len = 28 other = 1 binsiz = 2 y = logical 0 y = logical 0 bins = 13 14 other = 1 len = 27 other = 1 binsiz = 2 y = logical 0 y = logical 0 bins = 15 14 other = 1 len = 29 other = 1 binsiz = 2 y = logical 0 y = logical 0 bins = 11 15 other = 1 len = 26 other = 1 binsiz = 2 y = logical 0 bins = 14 12 other = 1 len = 26 other = 1 binsiz = 2 y = logical 0 y = logical 0 bins = 13 12 other = 1 len = 25 other = 1 binsiz = 2 y = logical 0 y = logical 0 bins = 15 12 other = 1 len = 27 other = 1 binsiz = 2 y = logical 0 bins = 14 12 other = 1 len = 26 other = 1 binsiz = 2 y = logical 0 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;

bins = 13 24 23 18 20 5 other = 1 len = 103 other = 1 binsiz = 6 bins = 28 22 27 18 14 other = 1 len = 109 other = 1 binsiz = 5 bins = 12 24 22 17 20 7 other = 1 len = 102 other = 1 binsiz = 6 bins = 7 26 14 23 22 10 other = 1 len = 102 other = 1 binsiz = 6 bins = 14 22 19 20 17 10 other = 1 len = 102 other = 1 binsiz = 6 bins = 8 22 18 16 26 18 other = 1 len = 108 other = 1 binsiz = 6 bins = 24 23 13 17 24 other = 1 len = 101 other = 1 binsiz = 5 bins = 12 16 17 24 24 9 other = 1 len = 102 other = 1 binsiz = 6 bins = 25 14 26 19 22 2 other = 1 len = 108 other = 1 binsiz = 6 bins = 22 19 15 19 28 5 other = 1 len = 108 other = 1 binsiz = 6

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;

bins = 53 0 0 0 55 other = 1 len = 108 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 54 0 0 0 53 other = 1 len = 107 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 53 0 0 51 other = 1 len = 104 other = 1 binsiz = 4 y = logical 0 y = logical 0 bins = 51 0 0 55 other = 1 len = 106 other = 1 binsiz = 4 y = logical 0 y = logical 0 bins = 53 0 0 0 53 other = 1 len = 106 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 54 0 0 0 53 other = 1 len = 107 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 53 0 0 51 other = 1 len = 104 other = 1 binsiz = 4 y = logical 0 y = logical 0 bins = 54 0 0 0 54 other = 1 len = 108 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 53 0 0 54 other = 1 len = 107 other = 1 binsiz = 4 y = logical 0 y = logical 0 bins = 52 0 0 51 other = 1 len = 103 other = 1 binsiz = 4 y = logical 0 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;

bins = 71 19 5 3 1 0 1 0 1 0 0 0 1 other = 1 len = 102 other = 1 binsiz = 13 y = logical 0 bins = 98 1 0 0 0 1 0 0 0 0 0 0 0 0 1 other = 1 len = 101 other = 1 binsiz = 15 y = logical 0 bins = 98 1 0 1 2 0 1 1 other = 1 len = 104 other = 1 binsiz = 8 y = logical 0 bins = 91 6 2 1 0 0 0 0 0 0 0 1 0 1 other = 1 len = 102 other = 1 binsiz = 14 y = logical 0 bins = 71 19 7 2 1 1 0 0 1 other = 1 len = 102 other = 1 binsiz = 9 y = logical 0 bins = 97 2 3 1 2 0 0 0 1 0 0 0 0 1 other = 1 len = 107 other = 1 binsiz = 14 y = logical 0 bins = 82 10 3 1 3 1 1 other = 1 len = 101 other = 1 binsiz = 7 y = logical 0 bins = 87 9 6 1 1 1 1 1 1 0 0 1 other = 1 len = 109 other = 1 binsiz = 12 y = logical 0 bins = 88 7 4 0 1 1 1 2 0 1 0 0 1 other = 1 len = 106 other = 1 binsiz = 13 y = logical 0 bins = 98 3 2 0 0 0 0 0 0 0 0 0 0 0 0 1 other = 1 len = 104 other = 1 binsiz = 16 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;

bins = 42 55 49 65 55 59 54 51 36 38 other = 1 len = 504 other = 1 binsiz = 10 bins = 55 50 61 44 49 50 52 55 42 52 other = 1 len = 510 other = 1 binsiz = 10 bins = 57 54 44 39 41 54 42 56 69 49 other = 1 len = 505 other = 1 binsiz = 10 bins = 44 43 59 52 58 46 57 60 40 46 other = 1 len = 505 other = 1 binsiz = 10 bins = 56 43 51 53 42 49 57 53 50 53 other = 1 len = 507 other = 1 binsiz = 10 bins = 49 41 49 47 50 57 51 56 51 52 other = 1 len = 503 other = 1 binsiz = 10 bins = 47 54 60 59 63 41 46 54 37 49 other = 1 len = 510 other = 1 binsiz = 10 bins = 66 45 37 43 59 43 50 46 66 52 other = 1 len = 507 other = 1 binsiz = 10 bins = 34 52 47 60 54 44 56 55 49 52 other = 1 len = 503 other = 1 binsiz = 10 bins = 51 55 45 55 49 52 47 48 56 48 other = 1 len = 506 other = 1 binsiz = 10

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;

bins = Columns 1 through 30 445 48 2 0 2 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 32 1 1 other = 1 len = 504 other = 1 binsiz = 32 y = logical 0 bins = Columns 1 through 30 486 9 2 2 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 43 0 0 0 0 0 0 0 0 0 0 0 0 1 other = 1 len = 503 other = 1 binsiz = 43 y = logical 0 bins = 472 17 4 2 0 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 other = 1 len = 501 other = 1 binsiz = 30 y = logical 0 bins = Columns 1 through 30 498 4 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 63 0 0 1 other = 1 len = 504 other = 1 binsiz = 63 y = logical 0 bins = Columns 1 through 30 482 15 1 2 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 43 0 0 0 0 0 0 0 0 0 0 0 1 1 other = 1 len = 504 other = 1 binsiz = 43 y = logical 0 bins = Columns 1 through 30 377 60 29 10 5 4 1 3 2 4 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 Columns 31 through 37 0 0 0 0 0 0 1 other = 1 len = 501 other = 1 binsiz = 37 y = logical 0 bins = Columns 1 through 30 413 75 7 2 1 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 other = 1 len = 502 other = 1 binsiz = 49 y = logical 0 bins = Columns 1 through 30 322 128 25 11 8 1 4 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 Columns 31 through 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 other = 1 len = 504 other = 1 binsiz = 49 y = logical 0 bins = Columns 1 through 30 434 33 12 5 8 3 0 1 0 0 2 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 62 0 1 other = 1 len = 502 other = 1 binsiz = 62 y = logical 0 bins = Columns 1 through 30 427 45 10 7 3 1 2 2 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 41 0 0 0 0 0 0 0 0 0 0 1 other = 1 len = 501 other = 1 binsiz = 41 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;

bins = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 Columns 31 through 43 0 0 0 2 0 0 3 1 3 2 5 29 454 other = 1 len = 502 other = 1 binsiz = 43 y = logical 0 bins = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 46 0 0 0 1 0 0 1 0 0 1 0 2 1 11 23 462 other = 1 len = 503 other = 1 binsiz = 46 y = logical 0 bins = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 Columns 31 through 41 0 1 0 2 0 0 6 4 12 30 440 other = 1 len = 501 other = 1 binsiz = 41 y = logical 0 bins = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 Columns 31 through 44 2 0 0 0 0 0 0 3 2 3 2 10 50 431 other = 1 len = 505 other = 1 binsiz = 44 y = logical 0 bins = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 50 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 2 4 7 43 442 other = 1 len = 502 other = 1 binsiz = 50 y = logical 0 bins = 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 2 1 2 8 6 29 450 other = 1 len = 502 other = 1 binsiz = 30 y = logical 0 bins = 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 2 0 1 5 3 7 11 127 343 other = 1 len = 505 other = 1 binsiz = 29 y = logical 0 bins = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 53 0 0 0 0 0 0 0 0 0 2 0 0 0 4 1 0 2 1 4 8 13 172 297 other = 1 len = 505 other = 1 binsiz = 53 y = logical 0 bins = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 54 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 3 33 466 other = 1 len = 505 other = 1 binsiz = 54 y = logical 0 bins = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 Columns 31 through 40 0 0 0 0 1 1 2 7 10 477 other = 1 len = 502 other = 1 binsiz = 40 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;

bins = 254 0 0 0 252 other = 1 len = 506 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 252 0 0 0 251 other = 1 len = 503 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 253 0 0 0 254 other = 1 len = 507 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 253 0 0 0 251 other = 1 len = 504 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 252 0 0 0 253 other = 1 len = 505 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 253 0 0 0 254 other = 1 len = 507 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 252 0 0 0 254 other = 1 len = 506 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 251 0 0 0 253 other = 1 len = 504 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 251 0 0 0 254 other = 1 len = 505 other = 1 binsiz = 5 y = logical 0 y = logical 0 bins = 251 0 0 0 255 other = 1 len = 506 other = 1 binsiz = 5 y = logical 0 y = logical 0

10   Fail
% '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;

bins = 1 2 7 9 21 30 51 60 79 67 72 43 35 13 10 1 0 0 1 other = 1 len = 502 other = 1 binsiz = 19 [Warning: *** CAUTION: 1 faults recorded so far. ***] [> In ScoringEngineTestPoint10 (line 9) In solutionTest (line 23)] bins = 3 3 11 19 24 51 66 76 74 70 42 36 16 4 4 3 3 other = 1 len = 505 other = 1 binsiz = 17 [Warning: *** CAUTION: 2 faults recorded so far. ***] [> In ScoringEngineTestPoint10 (line 9) In solutionTest (line 23)] bins = 1 4 7 13 22 48 74 87 74 60 56 36 9 5 3 0 2 other = 1 len = 501 other = 1 binsiz = 17 [Warning: *** CAUTION: 3 faults recorded so far. ***] [> In ScoringEngineTestPoint10 (line 9) In solutionTest (line 23)]

Too many wrong assessments.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!