lundi 17 avril 2017

How do I generate random numbers in 3 lines - Linux Shell Script

I am new here, and have just made an account. I love to code, and currently I am stuck in a bit of a problem. I would like to write a code that can generate 3 rows of 6 random numbers spaced out, which shuffle after a given time (0.5 seconds), and no new rows are created, basically 6 random numbers keep generating in 3 rows. The code I have so far is:

echo " "

echo " "

echo " "



for i in {1..5};

do

for i in {1..1};

do


echo -ne " $(($RANDOM % 100))   $(($RANDOM % 100))   $(($RANDOM % 100))   $(($RANDOM % 100))   $(($RANDOM % 100))   $(($RANDOM % 100))\r"


done

sleep 0.5

done

However, when I try to add the second and third row to this, it doesn't seem to work the way I want it. A sample output could look like:

45 88 85 90 44 22

90 56 34 55 32 45

58 99 42 10 48 98

and between these numbers, new ones will generate, keeping only 6 columns and 3 rows. I have tried making matrix too but it didn't work for me. Any help would be great, and I am sorry if i missed any guideline as this is my first ever post.

Thanks




Aucun commentaire:

Enregistrer un commentaire