On Mon, Oct 12, 2009 at 10:14 AM, Damien Dusha <[email protected]> wrote:
> Dear all,
>
> I have come across some peculiar behaviour using $RANDOM in some shell
> scripts (in this case, to generate different random serial numbers for
> testing).
>
> It is best explained by example.  I have attached 3 shell scripts that
> illustrate the behaviour:
> * busybox_test_random_v1.sh uses $RANDOM in a function, where the
> function is called several times
> * busybox_test_random_v2.sh uses $RANDOM in several different
> functions, where the functions are called once each (but do the same
> thing)
> * busybox_test_random_v3.sh uses $RANDOM only in the body of the script.
>
> In _v1.sh and _v2.sh, the **same string** of numbers is generated when
> calls to the function are repeated

You are using $RANDOM in subshells, i.e. in child processes.
Thus they all share the same seed derived from parent's pid
and start time, and therefore generate the same "random" sequence.

Try this patch.

--
vda

Attachment: 5.patch
Description: Binary data

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to