Well that is quite a long story. Not everybody wants to read all this. And you are not very specific about what you are asking. From the title we learn: "Creating a link that takes the user to a random page". Is that what you want? Does it not give the expected result or do you get an error message?
You will have to elaborate on what is happening. Test your code bit by bit. Is it the function
You will have to elaborate on what is happening. Test your code bit by bit. Is it the function
util.list_entries()
that does not give the expected result?