Mailing List Archive

Support open source code!


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

Re: [tlug] random in bash [Kmail Notification]



On Thu, Mar 07, 2002 at 07:15:33PM +0900,
Antony Stace wrote:

> > 
> > Do anyone know how to do a "random" in bash ? I guess that would be the 
> > simpliest way to do that.
> 
> very crude....but
> 
> function rand
> {
>     TMPFILE=/tmp/BASHRANDOMTMPFILE.$$
>     /usr/bin/vmstat > $TMPFILE
>     /usr/bin/uptime >> $TMPFILE
>     /usr/bin/free   >> $TMPFILE
>     /sbin/ifconfig   >> $TMPFILE 
>     /bin/date   >> $TMPFILE 
>     cksum $TMPFILE | awk '{print $1}'
>     \rm $TMPFILE
> }

Well, if you're going to be platform dependent, you might as well use
the kernel random number generator.

function rand
{
perl -e 'open IN,"/dev/random" or die $!;sysread(IN,$r,4);print unpack("L",$r)'
}

The C equivalent is almost as short.

-- 
Shimpei Yamashita                               http://www.shimpei.org/
You can't have everything. Where would you put it?    -- Steve Wright


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links