Problem 43592. Sample from random roulette
Solution Stats
Problem Comments
-
8 Comments
Completely irrelevant test suite.
How would you test random output? : )
One possible way is to compute the empirical distribution based on a large number of random samples, and then compare the empirical distribution with the true distribution (up to a specified tolerance). Taking integer samples as an example, x = histcounts(data, [unique(data) Inf], 'Normalization','probability') returns the empirical probability of data.
That is exactly how the code validation is done (it mimics the central limit theorem), except I set the admissible variance sufficiently large in case someone ends up as outlier. Anyway, I changed it a little today so that "deterministic" solution does not get accepted any more...
Your test is very weak. It does not fully reflect the random sampling procedure.
See my new solution which takes advantage of the weakness of your test suite. It is essentially "deterministic", but it passes your test.
Hi, Jakub. One more fairly simple check you could add would be to ensure that the result of diff( output ) does not produce mostly zeros. .... BTW, you do not need to put all checks inside one assert command. Indeed, it may be helpful for players to know which assertion is tripping them up, with the addition of text error messages. —DIV
To be fair, Jakub, it is certainly a lot of work to set up a robust Test Suite for this problem. It is not possible to make a perfect Test Suite that will stop all cheating, so the plan would be just to make cheating difficult in comparison to a genuine solution. BTW, the leeway you allow on the sums (±50%) seems too generous. According to https://www.mathworks.com/matlabcentral/cody/problems/43592-sample-from-random-roulette/solutions/1351272 it seems ±2% would be about right, or perhaps ±5% if you still want to be extremely conservative / very generous.
Solution Comments
Show commentsProblem Recent Solvers21
Suggested Problems
-
Sum of diagonal of a square matrix
1575 Solvers
-
Cell Counting: How Many Draws?
1901 Solvers
-
177 Solvers
-
Matlab Basics - Set unwanted parts of a vector to zero
246 Solvers
-
Matlab Basics II - Unit Conversion
165 Solvers
More from this Author9
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!