implemented random selection algorithm to select ith element from array