Question: How do I create a function that returns a random element of a given list?

I want to create a random polynomial using randpoly() with coefficients in a given list A := [1,1,2,5,6].

For that, I need to create a function that works as rand(1..9) but that when called returns a random element of A instead of a random number between 1 and 9.

What I have tried so far is

r := rand(1..numelems(A))
A[r()]

However, that returns a random element of A, not a function that returns a random element of A.

I've also tried

rand(A(1..numelems(A)))

But that gives an error.

One way of solving this problem would be to find out how to create a `..` type with the desired elements, something that works as 1..9 but with the elements of A. But convert(A,`..`) doesn't work and the rest of the things I tried don't work either.

Please Wait...