I'm a complete novice when it comes to JS and my problem is I need to modify a script which our CMS uses. The CMS scripting language is a subset of JS so I'm hoping someone with expert JS knowledge will be able to help me with this.

The query is to select a list of links of a certain type (and subtype) from the database and I want to randomly display 2 of these, perferrably as an unordered list.

At the moment the result is sometimes 2 are displayed, sometimes as many as four. Also sometimes the links are repeated and I have no control over the output other than to put a <br /> between links.

Here's the code, any help gratafully appreciated:

Code:
function onParseStart()
{
  var subtypeId = 5;	   // id of your subtype
  var objTypeId = 4;		// id of the object type
  var list  = new WebObjectList();
  
  list.select("Select w.id, w.type from webobjects w, objelink e where w.id = e.object_id and w.type = '"+objTypeId+"' and w.subtype='"+subtypeId+"'");
  var count = list.length;
 for(var i=0;i<2;i++)
 {
  list[Math.floor(Math.random()*count)].parse();
  write ("<br />");
 }
  return Handler.ABORT;
}