dalhuijsen/bashnative — pull request #4 by pjkundert (2012-12-14 19:22:54+00:00)
Title: Corrected rand and rand_element functions

The 'rand N' function is supposed to return a value in the range (0, N] non-inclusive; it was incorrectly using 32767 as a divisor for RANDOM instead of 32768, erroneously returning the value N occasionally (once every 32K calls, on average).

The 'rand_element ...' function is supposed to return a random instance of one of its N arguments. It would never return the first argument.

Added unit tests to z_build/tdd.sh to test the rand and rand_element. Ensures that rand respects the range (0,N] and maintains a reasonable statistical distribution, and that rand_element returns every one of its arguments, and never returns anything else.