Re: Problems when RANDOM without $ is used as an array index

2010-01-20 Thread DennisW
On Jan 20, 7:28 am, Stephane CHAZELAS wrote: > 2010-01-12 22:07:31 -0500, Chet Ramey: > > > > > On 1/12/10 5:16 AM, Stephane CHAZELAS wrote: > > > 2010-01-11, 17:42(-05), Chet Ramey: > > Think of it as > > > x = $(( RANDOM%6+1 + RANDOM%6+1 )) > > y = dice[x] > > dice[RANDOM%6+1

Re: Problems when RANDOM without $ is used as an array index

2010-01-20 Thread Stephane CHAZELAS
2010-01-12 22:07:31 -0500, Chet Ramey: > On 1/12/10 5:16 AM, Stephane CHAZELAS wrote: > > 2010-01-11, 17:42(-05), Chet Ramey: > Think of it as > > x = $(( RANDOM%6+1 + RANDOM%6+1 )) > y = dice[x] > dice[RANDOM%6+1 + RANDOM%6+1] = y + 1 > return y > >>> [...] > >>> > >>

Re: Problems when RANDOM without $ is used as an array index

2010-01-12 Thread Chet Ramey
On 1/12/10 5:16 AM, Stephane CHAZELAS wrote: > 2010-01-11, 17:42(-05), Chet Ramey: Think of it as x = $(( RANDOM%6+1 + RANDOM%6+1 )) y = dice[x] dice[RANDOM%6+1 + RANDOM%6+1] = y + 1 return y >>> [...] >>> >>> I would still consider that a bug. >> >> OK. But everyone

Re: Problems when RANDOM without $ is used as an array index

2010-01-12 Thread Stephane CHAZELAS
2010-01-11, 17:42(-05), Chet Ramey: >> > Think of it as >> > >> > x = $(( RANDOM%6+1 + RANDOM%6+1 )) >> > y = dice[x] >> > dice[RANDOM%6+1 + RANDOM%6+1] = y + 1 >> > return y >> [...] >> >> I would still consider that a bug. > > OK. But everyone does it the same way. Except for pdksh, mksh, posh

Re: Problems when RANDOM without $ is used as an array index

2010-01-11 Thread DennisW
On Jan 11, 3:53 pm, Stephane CHAZELAS wrote: > 2010-01-11, 15:59(-05), Chet Ramey: > [...]> Think of it as > > > x = $(( RANDOM%6+1 + RANDOM%6+1 )) > > y = dice[x] > > dice[RANDOM%6+1 + RANDOM%6+1] = y + 1 > > return y > > [...] > > I would still consider that a bug. > > I don't think anyone would

Re: Problems when RANDOM without $ is used as an array index

2010-01-11 Thread Chet Ramey
> > Think of it as > > > > x = $(( RANDOM%6+1 + RANDOM%6+1 )) > > y = dice[x] > > dice[RANDOM%6+1 + RANDOM%6+1] = y + 1 > > return y > [...] > > I would still consider that a bug. OK. But everyone does it the same way. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer

Re: Problems when RANDOM without $ is used as an array index

2010-01-11 Thread Stephane CHAZELAS
2010-01-11, 15:59(-05), Chet Ramey: [...] > Think of it as > > x = $(( RANDOM%6+1 + RANDOM%6+1 )) > y = dice[x] > dice[RANDOM%6+1 + RANDOM%6+1] = y + 1 > return y [...] I would still consider that a bug. I don't think anyone would expect x to be incremented by 2 in a[++x]++ and it doesn't in any

Re: Problems when RANDOM without $ is used as an array index

2010-01-11 Thread Stephane CHAZELAS
2010-01-11, 14:26(+00), Stephane CHAZELAS: > 2010-01-9, 06:23(-06), den...@netstrata.com: > [...] >> This produces the correct distribution of dice values for two six-sided dice: >> >> $ unset dice; for i in {1..1}; do ((dice[$RANDOM%6+1 + >> $RANDOM%6+1]++)); done; echo "${di...@]}" >> 290

Re: Problems when RANDOM without $ is used as an array index

2010-01-11 Thread Chet Ramey
On 1/11/10 9:26 AM, Stephane CHAZELAS wrote: > 2010-01-9, 06:23(-06), den...@netstrata.com: > [...] >> This produces the correct distribution of dice values for two six-sided dice: >> >> $ unset dice; for i in {1..1}; do ((dice[$RANDOM%6+1 + >> $RANDOM%6+1]++)); done; echo "${di...@]}" >> 29

Re: Problems when RANDOM without $ is used as an array index

2010-01-11 Thread Stephane CHAZELAS
2010-01-9, 06:23(-06), den...@netstrata.com: [...] > This produces the correct distribution of dice values for two six-sided dice: > > $ unset dice; for i in {1..1}; do ((dice[$RANDOM%6+1 + $RANDOM%6+1]++)); > done; echo "${di...@]}" > 290 582 837 1130 1375 1635 1315 1126 845 574 291 > > The

Problems when RANDOM without $ is used as an array index

2010-01-09 Thread dennis
Configuration Information [Automatically generated, do not change]: Machine: i486 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='ba