[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sr #105800] Random number generator builtin
From: |
Eric Blake |
Subject: |
[sr #105800] Random number generator builtin |
Date: |
Mon, 26 Mar 2007 16:06:00 +0000 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 |
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/