Fixed cast bug

Ensure the result of random() is multiplied by the number of array
indices before casting to int. Otherwise index is always 0.