From f485c3303a579bd4f135730164d9a0dd22d8f646 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Einar=20J=C3=B8rgen=20Haraldseid?= Date: Mon, 12 Jun 2017 14:49:31 +0200 Subject: [PATCH 1/1] =?utf8?q?Bedre=20m=C3=A5te=20=C3=A5=20vite=20array-st?= =?utf8?q?=C3=B8rrelsen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- middag.sh | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/middag.sh b/middag.sh index 9f2b66b..dbb0e14 100755 --- a/middag.sh +++ b/middag.sh @@ -24,28 +24,13 @@ Sides=( 'salat' ) -PrepCount=0 -while [ "x${Prep[PrepCount]}" != "x" ]; do - ((PrepCount++)) -done - -MeatCount=0 -while [ "x${Meat[MeatCount]}" != "x" ]; do - ((MeatCount++)) -done - -SideCount=0 -while [ "x${Sides[SideCount]}" != "x" ]; do - ((SideCount++)) -done - PrepN=$RANDOM -(( PrepN %= $PrepCount )) +(( PrepN %= ${#Prep[@]} )) MeatN=$RANDOM -(( MeatN %= $MeatCount )) +(( MeatN %= ${#Meat[@]} )) SideN=$RANDOM -(( SideN %= $SideCount )) +(( SideN %= ${#Sides[@]} )) echo "${Prep[PrepN]} ${Meat[MeatN]} med ${Sides[SideN]}" -- 2.30.2