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

Re: funny subshell effect



On Mar 10, 12:18am, Mikael Magnusson wrote:
} Subject: funny subshell effect
}
} % repeat 3; do command echo .(e:REPLY=\$RANDOM:); done
} 5801
} 5801
} 5801
} 
} Is this something that must be so?

Yep, it's intentional.  Read the manual:

     The values of RANDOM form an intentionally-repeatable pseudo-random
     sequence; subshells that reference RANDOM will result in identical
     pseudo-random values unless the value of RANDOM is referenced or
     seeded in the parent shell in between subshell invocations.

Above that, "The random number generator can be seeded by assigning a
numeric value to RANDOM."

% for i in {1..3}; do command echo .(e:RANDOM=$i\;REPLY=\$RANDOM:); done
17767
6138
20026

If you're not generating more than one number per second, a good way
to see the generator is with $SECONDS.  Or if your system supports a
higher granularity clock, something like

    typeset -F SECONDS
    repeat 3; do
      command echo .(e:'RANDOM=$((SECONDS*1000));REPLY=$RANDOM':);
    done

Consequently, Phil ... your approach may be reasonable, but we don't
want to apply it. :-)



Messages sorted by: Reverse Date, Date, Thread, Author