This script keeps throwing an error...

This script keeps throwing an error...

I am trying to display records in a HTML View with certain fields in a random order,  but it keeps generating an error:


Error details:
Error occured while executing the script.
sublist operation failed as the 'end' index(5) is greater than the list size(1) 



This is my code:

  1. htmlpage Test(recID)
    <%{%>





    <%ran = zoho.currenttime.toLong();%>





    <%record = Make_Test [ID = input.recID.toLong()];
    qlist = record.idlist;%>





    <%for each q in Question [ID in qlist] sort by Added_Time ,Added_User_IP_Address ,Enter_Correct_Answer ,Enter_Question desc
    {%>





    <br/>
    <br/>
    Topic is <%=q.Topic%>
    <br/>
    <br/>
    Question is <%=q.Enter_Question%>
    <br/>
    <%ran = ((input.recID.toLong() * ran) % 5);%>





    <br/>
    <%alist = List();
    alist.add(q.Enter_Correct_Answer);
    alist.add(q.Enter_Incorrect_Answer_1);
    alist.add(q.Enter_Incorrect_Answer_2);
    alist.add(q.Enter_Incorrect_Answer_3);
    alist.add(q.Enter_Incorrect_Answer_4);
    alist.add(q.Enter_Correct_Answer);
    alist.add(q.Enter_Incorrect_Answer_1);
    alist.add(q.Enter_Incorrect_Answer_2);
    alist.add(q.Enter_Incorrect_Answer_3);
    alist.add(q.Enter_Incorrect_Answer_4);
    for each a in alist.subList(ran)
    {
    }%>

    <%for each t in a.toList().subList(0, 5)
    {%>



    <%=t%>



    <br/>
    <br/>

    <%}
    }%>





    <br/>
    <br/>














































































  1. <%}%>
As Creator has no random sort function I am trying to create my own...

@ZC is there some way to do this?

Thanks,
Damien.