dimanche 15 mars 2015

I need to enable interactivity/ user input for a simple random number generator script for LINUX

I am new to script writing and draw exclusively from the internet to learn, so please help me as if you were talking to a child. That being said, I am writing a C shell script that takes numeric input x and generates x random numbers. I made alterations/simplification to a script I found online to generate random numbers but I can't figure out how to use read function to generate x numbers.


Here's what I got:



awk -v NUM=$1 -v TOPNUM=$2 '

BEGIN {

if (NUM <= 0)

NUM = 5

if (TOPNUM <= 0)

TOPNUM = 10000

srand() for (j = 1; j <= NUM; ++j) {

do {

select = 1 + int(rand() * TOPNUM)

} while (select in pick)

pick[select] = select

}
for (j in pick)

printf("%s ", pick[j])

printf("\n")

}'


In line 4, I ask the script to generate 5 numbers with a range of 1 to 10000. I tried, and if I had hair, I'd have pulled it out in despair, to set variables, etc...


I'm lost.


I tried


Help?





Aucun commentaire:

Enregistrer un commentaire