I have an array that has only had specific keys set. The array will look something like
arr[0] = 'undefined';
arr[1] = '16';
arr[2] = 'undefined';
arr[3] = '13';
arr[4] = 'undefined';
arr[5] = 'undefined';
arr[6] = '24';
arr[7] = 'undefined';
From that particular array I would want to randomly select either 16, 13, or 24.
Is there a good way to do this?
Thanks,
Sam
Make a new array consisting of the indexes of the entries of your original array that you wish to consider (e.g.
{1, 3, 5}in your case); then pick a random element (in whichever way that satisfies your statistical requirements) from the index array and then retrieve the corresponding value.