Dan Cernat said:
Don't top post in this NG
{reformatted}
it
O(NlogN)???
Look up in your documentation the function rnd -> it returns a random
integer from 0 to RAND_MAX
Your function becomes trivial now, isnt it?
I just cannot stop wonder, O(NlogN)???
/dan
Hmmmm, I must not have explianed well.
I need random subSET of a RANGE of integers
So The function does not get a data structure holding integers from which to
choose. It just gets two integers: a BeginRange and EndRange
Then it needs to give me a data structure, most likely a std::vector that
holds a subSET of integers from that ranger that have been randomly picked.
For the returned integers to be a SET, they must all be unique.
So the algorithm must pick out an integer from the Range and add it to the
vector, then pick out another number from the Range that has not already
been picked.
The first algorithm that came to mind was to just discard the number if it
has already been picked and try to pick again, but this doesn't work very
well when the subset size approaches the size of the range.
The next approach that I thought of would be to increment up the list when
an integer has been picked that has already been picked, so if integer 10
were to be generated by the random number generator, then try 11, if that
has already been picked, try 12 and so on. The problem with this approach
is that it makes numbers close to numbers that have already been picked MORE
likely to be picked. So this algorithm is FAULTY.
So the final algorithm that I thought of was a but more complicated, and not
so easy to code, I will post a description of it by request, but it led me
to desire to find a library that has a function that already does this.
Thanks again for your help guys,
-Chris