Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Random numbers in functions
- X-seq: zsh-users 12247
- From: Atom Smasher <atom@xxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Random numbers in functions
- Date: Wed, 21 Nov 2007 20:25:07 +1300 (NZDT)
- In-reply-to: <Pine.GSO.4.61.0711201241340.5718@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Openpgp: id=0xB88D52E4D9F57808; algo=1 (RSA); size=4096; url=http://atom.smasher.org/pgp.txt
- References: <Pine.GSO.4.61.0711201241340.5718@xxxxxxxxxx>
On Tue, 20 Nov 2007, Justin M Wozniak wrote:
Are there any other solutions?
===================
typeset -F SECONDS
typeset -F 6 SECONDS
print $[ ${SECONDS/./} % 10 ]
that will give "random" numbers between 0-9. adjust to just about any
range you need.
or seed RANDOM like this:
typeset -F SECONDS
typeset -F 6 SECONDS
RANDOM=${SECONDS/./}
print $RANDOM
in both examples the `typeset` will only have to be done once per
function.
--
...atom
________________________
http://atom.smasher.org/
762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
-------------------------------------------------
"As democracy is perfected, the office of president
represents, more and more closely, the inner soul
of the people. On some great and glorious day the
plain folks of the land will reach their heart's
desire at last and the White House will be adorned
by a downright moron."
-- H. L. Mencken, 1920
Messages sorted by:
Reverse Date,
Date,
Thread,
Author