Use the rand()* method to get a random value between 1 and 10 inclusive. Create a SELECT clause by concatenating the number to the base column id, and pass that to the database. Something like:
column = rand(1..10)
string select = "SELECT ans" + column + "remainder of select clause"
* you have not mentioned what language you are using so the above is only pseudocode.