mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
Estimated hours taken: 1.5 Branches: main library/random.m: Provide better documentation on how (not) to use the random number generator in the standard library. Generators of this kind are very sensitive to the way in which they are used, and if used in a way not anticipated they can give very poor results. XXX The standard library really should provide a better quality RNG. There is still a place for quick and dirty RNGs like this one, though, provided users are given adequate information about the pitfalls. One of the pitfalls to avoid is that you shouldn't use mod (or rem) to reduce a number down to some desired range, you should use something like div. We therefore provide a predicate that does this the prescribed way. We also provide a predicate that is similar to randmax, but returns the number of distinct random numbers that can be generated instead of the maximum. Fix random__permutation to avoid the above pitfall. Replace some occurrences of is/2 with =/2. NEWS: Mention the new predicate. tests/hard_coded/Mmakefile: tests/hard_coded/random_permutation.exp: tests/hard_coded/random_permutation.m: A test case for random__permutation. We don't test that the result is "random", but we at least test that it is a permutation. tests/hard_coded/random_simple.exp: tests/hard_coded/random_simple.m: A simple test that checks for off-by-one errors in random__random/5. tests/hard_coded/stable_sort.m: tests/hard_coded/test_bitset.exp: tests/hard_coded/test_bitset.m: Fix these tests to avoid the above pitfall. The bitset tester also needed to be modified so that it doesn't output anything that may depend on the particular random sequence generated.
3 lines
26 B
Plaintext
3 lines
26 B
Plaintext
Test passed.
|
|
Test passed.
|