groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] [PATCH] Use bash for several contrib scripts


From: Ralph Corderoy
Subject: Re: [Groff] [PATCH] Use bash for several contrib scripts
Date: Fri, 03 Jan 2014 10:55:58 +0000

Hi,

Tethys wrote:
> Since it's not guaranteed to be present, why not just ignore $RANDOM
> and use our own randomly generated integer instead?  Something like:
> 
>       groff_rand=$(dd if=/dev/urandom bs=8 count=1 2>/dev/null | sum | sed 
> 's/^0*//;s/ .*//')
>       tmp="$d/eqn2graph$groff_rand"
> 
> should work and be portable. I think pretty much everywhere supports
> /dev/urandom, right?

Nope.  :-)

> If not we could use /dev/random with the minimal
> chance of it blocking.

That neither AIUI.

My awk(1posix), package manpages-posix, makes clear that

    $ awk 'BEGIN {srand(); print int(rand() * 0x8000)}'
    16769
    $

should be a portable replacement for bash's RANDOM, though it gives the
same answer for the whole second.  Can we count on a POSIX awk, i.e. not
oawk still called awk;  Hi Solaris!  More digits,

    awk 'BEGIN {srand(); print substr(sprintf("%.8f", rand()), 3)}'

Cheers, Ralph.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]