I'd forgotten that one, thanks for reminding me.
For those interested, you can find it in the bash man page w/ a case sensitive search for 'RANDOM'.
The bash code to map $RANDOM onto a range of characters is easy; in fact, the integer arithmetic assists by truncating the division. The "fun" part would come if you wanted to pick from a discontinuous set, say, letters & numbers, but no special characters.
Further fun is available in designing options for the function or program, allow or disallow upper case, for instance.
I got interested in the randomness of $RANDOM, so I wrote a little program to spit out n random lower case letters, count the number of instances of each letter, & sort the results. I tested on runs of 260, 2600, 26000, & 260000. (A run of 260000 took a minute or so on a 1 GHz P3.)
As expected, there was variation in the high & low counts & the difference converged w/ increasing n. I don't remember enough statistics to properly analyze the results, but my eyeball says there is a tendency for the median to be greater than the mean.
|