From: Daniele Fua <fua@g24ux.phys.uniroma1.it>
Subject: sh script
Date: 1998/11/04 [thread overview]
Message-ID: <36406956.3F54@g24ux.phys.uniroma1.it> (raw)
[-- Attachment #1: Type: text/plain, Size: 732 bytes --]
Anyone can suggest why the attached small sh script for pseudo random
number generation [0-99] is not able to keep the variable $rand outside
the scope of the while loop? Any suggested fix?
My operating system is Digital UNIX V4.0D
Thanks
--
===================================================================
| Daniele Fua` G24 | E-mail: fua@g24ux.phys.uniroma1.it |
| Dept. of Physics | Phone : +39 06 4991 3515 |
| Universita` "La Sapienza" | Fax : +39 06 4991 3522 |
| P.le A. Moro, 2 | |
| 00185 Roma, Italy | |
===================================================================
[-- Attachment #2: random --]
[-- Type: text/plain, Size: 233 bytes --]
#! /usr/bin/sh
#rand=`expr 1`
/bin/ps -e -o pid | while read mypid
do
if [ "${mypid}" != "PID" ]; then
rand=`expr \( "${rand}" + "${mypid}" \) % 100`
fi
echo "inside loop: rand=" ${rand}
done
echo "outside loop: rand=" ${rand}
next reply other threads:[~1998-11-04 5:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-11-04 5:00 Daniele Fua [this message]
1998-11-04 5:00 ` sh script Daniele Fua
1998-11-04 5:00 ` Allan Hawdon
1998-11-11 5:00 ` Finnbarr P. Murphy
1998-11-12 5:00 ` Robert Klima
2000-01-26 5:00 ` Loris Renggli
2000-01-26 5:00 ` Daniel S. Riley
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox