Your code is wrong. What is happening is that the random number generated can potentially be 4 because the length of the array is 4. However an Array is zero based meaning it starts counting at 0 not 1. Therefore you need to have msgs.length-1. Like so: When you are using Math.floor you do not need to subtract 1 from the length of the array
js code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){
if(activated && contact.Name==Origin) ChatWnd.SendMessage(msgs[Math.floor(Math.random()*msgs.length)]);
}
You need to use Math.floor not Math.ceil. Math.floor will round down to the nearest integer where Math.ceil rounds upwards.