Help with AWK and RANDOM please

Hi, here's what I'm trying to do,

I used awk to separate numbers from a file into a list like this:

4536
23426
452
7647
35637
35635
35653

Now I need to randomly select one of this numbers, and make it a variable.

Any ideas on how to do this??

Thank you!

If you have the list in an array in awk you can use the rand() function:

index=int(rand()*NumberOfElements+1)
print array[index]

Regards

Thanks! Will this only select one of the numbers from the list?

Yes, but the best way to get the answer is to try it out for yourself.....:wink:

Regards

I would if I knew how :confused:

This may be a dumb question, but how do I get the list in an array?

Thanks.

This is an example how to fill an array "arr" with the value of the first field of a file and print a random element of the array.

awk '
{arr[++i]=$1}
END{srand()
element=int(rand()*i+1)
print arr[element]
}' file

Regards