my program is to use random pick,Exp, if i have picked array[1],array[2],then the next step i must choose array[3] and array[4].
In an array of 4 elements,exp:{"a","b","c",'d' }.ifa,b have been used or select,how to by default,select c,d
One (not the best) way is to keep additional array containing indexes. In your case it will initially contain { 0, 1, 2, 3 };
Than you take random number 0..arr_sz-1, use it as an index of your a...d array and remove it from index array. E.g. you got '2'. It means, you select "c". Then you remove '2' and your index array; it becomes { 0,1,3 }. arr_sz becomes 3, and so on.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment