quote:
Originally posted by matty
blah why not do this
code:
var aWordArray = new Array ('Hello!', 'Hi!', 'Yo', 'Allo', 'Hiya', 'How are you?');
Debug.Trace(aWordArray[Math.round(Math.rand() * aWordArray.length + 1)]);
I think you actually mean this:
code:
var aWordArray = new Array ('Hello!', 'Hi!', 'Yo', 'Allo', 'Hiya', 'How are you?');
Debug.Trace(aWordArray[Math.floor(Math.rand() * aWordArray.length + 1)]);
And you should use Math.floor() rather than Math.round() anyway, this is because the use of rounding means that the first and last variable have only half of the probability of getting chosen as the others do. And with matty's code anywa, the addition of 1 would have meant that the array elements would have to start from 1 rather than zero.