Follow-up Comment #3, sr #105800 (project m4):

By the way, m4 1.4.x already has a pseudo-random generator: mkstemp (or
maketemp, if you want to be portable to 1.4.7 and earlier).  A bit gross, but
you could use something along these lines rather than relying on the bash
extension of $RANDOM that is not in all versions of /bin/sh; unfortunately it
does not reduce the number of forks, and generates only 31 bits (well, 36^6
rather than 2^31) of randomness:

dnl random(num): Evaluates to an unevenly distributed random number from
range 0..num-1
define([random],
[pushdef([_], mkstemp([0XXXXXX]))dnl
syscmd([rm ]_)dnl
eval([0r36:]_[ % $1]popdef([_]))])

To be a good random number generator, though, you need an even distribution. 
Your approach with printf $RANDOM, as well as my approach above, fails that
criteria when you take a modulus that is relatively prime to the number of
psuedo-random inputs.  Any good solution that provides random as a builtin
must make sure that the resulting distribution is evenly distributed.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/support/?105800>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/



_______________________________________________
Bug-m4 mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-m4

Reply via email to