Re: How can I get a random number in a UNIX shell script???

From: scriptOmatic (ScriptOmatic@ChironComputing.Com)
Date: 04/19/03

  • Next message: Sebastian Jaenicke: "Re: How can I get a random number in a UNIX shell script???"
    From: scriptOmatic <ScriptOmatic@ChironComputing.Com>
    Date: Fri, 18 Apr 2003 22:21:05 GMT
    
    

    "Dr. David Kirkby" wrote:
    >
    > I've written a UNIX shell script
    > http://www.medphys.ucl.ac.uk/~davek/teston
    >
    > that allows me to copy a software package to a remote machine, then
    > try to configure and build the software on that remote host. So I
    > might do something like this, to check package package-foo.tar.gz on 3
    > machines with 4 different configuration options, with the -T option
    > saying to do this is a unique directory.
    >
    > teston host1 -T package-foo
    > teston host1 -c '--with-threads' -T package-foo
    > teston host1 -c '--with-mpi' -T package-foo
    > teston host1 -c '--without-gsl' -T package-foo
    >
    > teston host2 -T package-foo
    > teston host2 -c '--with-threads' -T package-foo
    > teston host2 -c '--with-mpi' -T package-foo
    > teston host2 -c '--without-gsl' -T package-foo
    >
    > teston host3 -T package-foo
    > teston host3 -c '--with-threads' -T package-foo
    > teston host3 -c '--with-mpi' -T package-foo
    > teston host3 -c '--without-gsl' -T package-foo
    >
    > so package-foo.tar.gz gets configure/built on 3 hosts, with 4
    > different options to the configure script, in ****hopefully**** 4
    > different directories on each host.
    >
    > My problem is that I need to put each set of file into a separate
    > directory, as otherwise they mess each other up. Currently I'm using
    > as a directory $HOME/$REMOTE_HOSTNAME/$PID, where $PID is the PID on
    > the local machine from where this is started. There is no risk of
    > files from host1 interfering with those of host2, since they are in
    > different directories. But there is nothing preventing those with each
    > different configuration option screwing each other up on the same
    > host, as I can't guarantee the PIDs will be different each time.
    >
    > Hence I want a random number that is portable, so not relying on perl
    > or /dev/random. It doesn't need to by crytograpically secure, but
    > hopefully the risk of it producing the same number on the one system
    > is very small (say < 1 in 10^5).
    >
    > I don't want to use the systems 'rand' (or similar) and seed it from
    > the system's clock, since if these scripts are run in parallel (which
    > is what I would do on a multi-processor machine), there is every
    > chance that they will be seeded with the same number, as they would
    > start at the same time.
    >
    > Any thoughts? Perhaps the PID is reasonable, given the consequences
    > for it going wrong are not that huge, but I'd like to make it a bit
    > more robust, if only for peace of mind.
    >
    > --
    > Dr. David Kirkby,
    > Senior Research Fellow,
    > Department of Medical Physics,
    > University College London,
    > 11-20 Capper St, London, WC1E 6JA.
    > Tel: 020 7679 6408 Fax: 020 7679 6269
    > Internal telephone: ext 46408
    > e-mail davek@medphys.ucl.ac.uk

    /bin/ksh supports ${RANDOM} which is always some random number.
    Your shell is /bin/sh but you could simply do this
    RANDOM=`/bin/ksh -c 'echo $RANDOM'`

    -- 
    http://ftp.opensysmon.com is a shell script archive site with an
    open source system monitoring and network monitoring software package.
    Many platforms are supplied already compiled.
    

  • Next message: Sebastian Jaenicke: "Re: How can I get a random number in a UNIX shell script???"

    Relevant Pages

    • Re: How can I get a random number in a UNIX shell script???
      ... "Dr. David Kirkby" wrote: ... > that allows me to copy a software package to a remote machine, ... -- http://ftp.opensysmon.com is a shell script archive site with an open source system monitoring and network monitoring software package. ...
      (comp.unix.shell)
    • running an X windows process in background through ssh
      ... I'd like to write a shell script in csh (or something else if ... necessary) that ssh's to a remote machine, ... The problem is that ssh logs out immediately and kills the X11 ... but then the password prompt doesn't work properly because the next ...
      (comp.unix.shell)
    • Re: running an X windows process in background through ssh
      ... >I'd like to write a shell script in csh (or something else if ... >necessary) that ssh's to a remote machine, ... >but then the password prompt doesn't work properly because the next ...
      (comp.unix.shell)
    • Re: How can I get a random number in a UNIX shell script???
      ... > that allows me to copy a software package to a remote machine, ... > try to configure and build the software on that remote host. ... as I can't guarantee the PIDs will be different each time. ... plus the PID of the process on the remote machine. ...
      (comp.unix.solaris)
    • Re: How can I get a random number in a UNIX shell script???
      ... > that allows me to copy a software package to a remote machine, ... > try to configure and build the software on that remote host. ... as I can't guarantee the PIDs will be different each time. ... plus the PID of the process on the remote machine. ...
      (comp.unix.shell)