Why are my AI's moving to 0,0,0 sometimes

Instead of length try using last index. If length of array is 1 and you try to get a random value from 0 to 1 then the array index of 1 would be invalid. See if that solves the issue.