This works for me:
$selectedindex=4
If you want to randomise options, you could always do something like this:
$0selectedindex=Math.floor((Math.random()*($0.length-1)+1)
Whilst 2nd bullet lies outside scope of your questions, it serves to illustrate how 1st bullet could be applied / amended as req.