Cody

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

Solution 1945943

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 = 7 3 11 6 other = 1 len = 27 other = 1 binsiz = 4 bins = 5 6 13 3 other = 1 len = 27 other = 1 binsiz = 4 bins = 6 10 7 2 other = 1 len = 25 other = 1 binsiz = 4 bins = 11 4 6 1 other = 1 len = 22 other = 1 binsiz = 4 bins = 7 3 10 6 other = 1 len = 26 other = 1 binsiz = 4 bins = 8 9 2 3 other = 1 len = 22 other = 1 binsiz = 4 bins = 6 6 9 5 other = 1 len = 26 other = 1 binsiz = 4 bins = 8 11 5 2 other = 1 len = 26 other = 1 binsiz = 4 bins = 5 11 6 2 other = 1 len = 24 other = 1 binsiz = 4 bins = 11 7 4 4 other = 1 len = 26 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 = 15 11 other = 1 len = 26 other = 1 binsiz = 2 y = logical 0 bins = 15 15 other = 1 len = 30 other = 1 binsiz = 2 [Warning: *** CAUTION: 1 faults recorded so far. ***] [> In ScoringEngineTestPoint2 (line 9) In solutionTest (line 7)] bins = 12 13 other = 1 len = 25 other = 1 binsiz = 2 y = logical 0 bins = 13 12 other = 1 len = 25 other = 1 binsiz = 2 y = logical 0 bins = 15 14 other = 1 len = 29 other = 1 binsiz = 2 y = logical 0 bins = 13 14 other = 1 len = 27 other = 1 binsiz = 2 y = logical 0 bins = 13 12 other = 1 len = 25 other = 1 binsiz = 2 y = logical 0 bins = 13 12 other = 1 len = 25 other = 1 binsiz = 2 y = logical 0 bins = 13 15 other = 1 len = 28 other = 1 binsiz = 2 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 = 9 20 26 19 24 11 other = 1 len = 109 other = 1 binsiz = 6 bins = 8 25 20 21 22 13 other = 1 len = 109 other = 1 binsiz = 6 bins = 15 24 18 20 27 other = 1 len = 104 other = 1 binsiz = 5 bins = 20 18 27 26 18 1 other = 1 len = 110 other = 1 binsiz = 6 bins = 19 17 19 20 25 10 other = 1 len = 110 other = 1 binsiz = 6 bins = 5 14 21 25 25 13 other = 1 len = 103 other = 1 binsiz = 6 bins = 9 25 15 25 19 14 other = 1 len = 107 other = 1 binsiz = 6 bins = 24 22 19 17 20 4 other = 1 len = 106 other = 1 binsiz = 6 bins = 1 29 14 14 31 12 other = 1 len = 101 other = 1 binsiz = 6 bins = 7 18 25 22 16 17 other = 1 len = 105 other = 1 binsiz = 6

4   Fail
% 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 52 other = 1 len = 105 other = 1 binsiz = 4 y = logical 0 bins = 52 0 0 52 other = 1 len = 104 other = 1 binsiz = 4 [Warning: *** CAUTION: 1 faults recorded so far. ***] [> In ScoringEngineTestPoint4 (line 9) In solutionTest (line 11)] bins = 55 0 0 51 other = 1 len = 106 other = 1 binsiz = 4 y = logical 0 bins = 55 0 0 55 other = 1 len = 110 other = 1 binsiz = 4 [Warning: *** CAUTION: 2 faults recorded so far. ***] [> In ScoringEngineTestPoint4 (line 9) In solutionTest (line 11)] bins = 55 0 0 0 54 other = 1 len = 109 other = 1 binsiz = 5 y = logical 0 bins = 52 0 0 51 other = 1 len = 103 other = 1 binsiz = 4 y = logical 0 bins = 51 0 0 55 other = 1 len = 106 other = 1 binsiz = 4 y = logical 0 bins = 52 0 0 55 other = 1 len = 107 other = 1 binsiz = 4 y = logical 0 bins = 54 0 0 0 52 other = 1 len = 106 other = 1 binsiz = 5 y = logical 0 bins = 54 0 0 54 other = 1 len = 108 other = 1 binsiz = 4 [Warning: *** CAUTION: 3 faults recorded so far. ***] [> In ScoringEngineTestPoint4 (line 9) In solutionTest (line 11)]

Too many wrong assessments.

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 = 91 8 1 2 1 1 0 1 other = 1 len = 105 other = 1 binsiz = 8 y = logical 0 bins = 94 9 2 1 1 0 0 1 1 0 0 0 0 0 0 0 1 other = 1 len = 110 other = 1 binsiz = 17 y = logical 0 bins = 81 14 6 3 0 2 1 0 3 other = 1 len = 110 other = 1 binsiz = 9 y = logical 0 bins = 94 1 4 0 1 0 0 0 1 other = 1 len = 101 other = 1 binsiz = 9 y = logical 0 bins = 100 2 1 1 0 0 0 0 0 0 0 1 other = 1 len = 105 other = 1 binsiz = 12 y = logical 0 bins = 91 5 3 1 0 0 0 0 1 0 0 0 0 0 0 1 other = 1 len = 102 other = 1 binsiz = 16 y = logical 0 bins = 96 4 2 0 0 1 1 0 0 0 1 other = 1 len = 105 other = 1 binsiz = 11 y = logical 0 bins = 92 8 2 2 1 1 0 0 0 1 0 0 0 0 0 1 other = 1 len = 108 other = 1 binsiz = 16 y = logical 0 bins = 85 10 4 2 1 0 0 0 0 0 0 1 other = 1 len = 103 other = 1 binsiz = 12 y = logical 0 bins = 89 11 5 0 1 0 1 0 0 0 1 other = 1 len = 108 other = 1 binsiz = 11 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 = 39 43 37 53 60 50 69 50 50 58 other = 1 len = 509 other = 1 binsiz = 10 bins = 63 44 59 44 48 56 52 51 46 45 other = 1 len = 508 other = 1 binsiz = 10 bins = 47 48 52 54 47 47 54 51 56 47 other = 1 len = 503 other = 1 binsiz = 10 bins = 42 48 57 47 62 50 43 50 52 59 other = 1 len = 510 other = 1 binsiz = 10 bins = 52 51 37 46 52 54 59 57 53 47 other = 1 len = 508 other = 1 binsiz = 10 bins = 46 67 51 54 44 48 52 48 45 55 other = 1 len = 510 other = 1 binsiz = 10 bins = 47 57 60 53 49 43 45 46 59 50 other = 1 len = 509 other = 1 binsiz = 10 bins = 33 49 65 45 57 48 43 68 52 49 other = 1 len = 509 other = 1 binsiz = 10 bins = 46 44 39 55 58 49 57 56 42 59 other = 1 len = 505 other = 1 binsiz = 10 bins = 47 51 45 40 61 44 45 55 53 65 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 459 35 2 3 1 0 0 1 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 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 69 0 0 0 0 0 0 0 0 1 other = 1 len = 503 other = 1 binsiz = 69 y = logical 0 bins = Columns 1 through 30 498 2 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 0 0 0 0 0 0 0 0 0 0 0 1 other = 1 len = 501 other = 1 binsiz = 50 y = logical 0 bins = Columns 1 through 30 455 31 7 6 0 0 1 1 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 38 0 0 0 1 0 0 0 1 other = 1 len = 504 other = 1 binsiz = 38 y = logical 0 bins = Columns 1 through 30 403 63 13 5 6 0 1 2 1 3 0 2 1 0 0 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 68 0 0 0 0 0 0 0 1 other = 1 len = 502 other = 1 binsiz = 68 y = logical 0 bins = Columns 1 through 30 457 28 7 3 0 0 1 2 1 0 0 0 1 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 bins = Columns 1 through 30 271 181 27 8 4 2 0 0 1 2 1 0 2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 Columns 31 through 58 0 0 0 0 0 0 0 1 0 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 = 58 y = logical 0 bins = Columns 1 through 30 411 54 16 2 5 3 4 2 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 Columns 31 through 40 0 0 0 0 0 0 0 0 0 1 other = 1 len = 502 other = 1 binsiz = 40 y = logical 0 bins = Columns 1 through 30 427 44 13 8 2 5 1 0 1 0 0 0 1 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 = 503 other = 1 binsiz = 63 y = logical 0 bins = Columns 1 through 30 464 27 3 4 1 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 44 0 0 0 0 0 0 0 0 0 0 0 0 0 1 other = 1 len = 503 other = 1 binsiz = 44 y = logical 0 bins = 433 44 6 3 2 0 1 1 2 0 1 1 1 1 1 1 0 1 0 0 0 0 0 2 other = 1 len = 501 other = 1 binsiz = 24 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 1 0 2 0 0 0 0 0 1 0 0 1 0 0 Columns 31 through 45 1 1 1 1 2 2 2 0 3 2 7 12 22 124 319 other = 1 len = 505 other = 1 binsiz = 45 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 1 0 0 0 1 0 0 Columns 31 through 41 0 1 1 2 0 0 2 8 11 42 435 other = 1 len = 505 other = 1 binsiz = 41 y = logical 0 bins = Columns 1 through 30 1 0 0 0 0 1 0 1 0 0 0 0 0 2 0 0 0 1 0 1 0 0 3 0 1 1 2 2 5 16 Columns 31 through 32 52 412 other = 1 len = 501 other = 1 binsiz = 32 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 60 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 2 1 1 1 13 32 448 other = 1 len = 504 other = 1 binsiz = 60 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 57 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 3 59 438 other = 1 len = 504 other = 1 binsiz = 57 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 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 1 0 0 Columns 61 through 71 0 0 0 1 0 2 2 6 10 38 444 other = 1 len = 505 other = 1 binsiz = 71 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 1 Columns 31 through 38 1 1 2 2 2 4 33 455 other = 1 len = 502 other = 1 binsiz = 38 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 47 0 0 0 0 0 1 0 0 0 1 0 1 1 2 5 13 476 other = 1 len = 501 other = 1 binsiz = 47 y = logical 0 bins = 1 0 0 0 0 0 0 2 0 0 0 0 0 1 0 0 0 0 2 1 1 1 1 2 1 0 3 12 18 456 other = 1 len = 502 other = 1 binsiz = 30 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 57 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 2 3 22 472 other = 1 len = 502 other = 1 binsiz = 57 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 = 255 0 0 0 255 other = 1 len = 510 other = 1 binsiz = 5 [Warning: *** CAUTION: 1 faults recorded so far. ***] [> In ScoringEngineTestPoint9 (line 9) In solutionTest (line 21)] bins = 253 0 0 0 254 other = 1 len = 507 other = 1 binsiz = 5 y = logical 0 bins = 253 0 0 0 252 other = 1 len = 505 other = 1 binsiz = 5 y = logical 0 bins = 255 0 0 0 252 other = 1 len = 507 other = 1 binsiz = 5 y = logical 0 bins = 254 0 0 0 252 other = 1 len = 506 other = 1 binsiz = 5 y = logical 0 bins = 251 0 0 0 253 other = 1 len = 504 other = 1 binsiz = 5 y = logical 0 bins = 251 0 0 0 252 other = 1 len = 503 other = 1 binsiz = 5 y = logical 0 bins = 254 0 0 0 253 other = 1 len = 507 other = 1 binsiz = 5 y = logical 0 bins = 252 0 0 0 255 other = 1 len = 507 other = 1 binsiz = 5 y = logical 0 bins = 254 0 0 0 253 other = 1 len = 507 other = 1 binsiz = 5 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 = 2 9 18 27 45 64 72 73 74 47 34 17 14 2 2 1 other = 1 len = 501 other = 1 binsiz = 16 [Warning: *** CAUTION: 1 faults recorded so far. ***] [> In ScoringEngineTestPoint10 (line 9) In solutionTest (line 23)] bins = 1 2 7 17 28 54 62 81 77 60 51 37 15 9 2 2 other = 1 len = 505 other = 1 binsiz = 16 [Warning: *** CAUTION: 2 faults recorded so far. ***] [> In ScoringEngineTestPoint10 (line 9) In solutionTest (line 23)] bins = 1 2 6 16 36 47 65 85 72 76 40 32 11 5 6 0 1 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.

Suggested Problems

More from this Author31

Community Treasure Hunt

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

Start Hunting!