Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Random numbers in functions



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