Ron Shepard <
ron-s...@nospam.comcast.net> wrote:
(snip)
> Michel Olagnon <
mola...@ifremer-a-oter.fr> wrote:
(snip)
>> For instance, generate 100 random values, rank them, and take the values
>> of A in the order that comes out of the ranking. Not optimal, but fun.
> This would require N*log(N) or N^2 effort, depending on how the sort
> is done. That is too much work.
Since N isn't given, it is hard to say how much work it
actually is. For small N it shouldn't be bad, and even
for medium or large N, not so bad.
> This is outside of my field, but I think the previous
> algorithm based in pairwise swaps is probably the right approach.
> It requires only N effort.
Hmm. Seems to me that it should be more than O(N) to get
a good amount of randomness. There are O(N**2) pairs, but
I might believe that O(N logN) swaps are enough.
> However, I think you need to be careful with boundaries so that
> every element has an equal chance of being swapped.
> The first approach I thought about would have resulted in
> smaller probabilities for the two end values than for the
> internal values.
It isn't bad to be sure that every element has an equal chance to
be swapped, but I don't believe that is necessary. All that is
needed is for each to have an equal probaility of ending up in
any position.
Well, equal probability of ending in each position isn't all,
but it isn't necessary that the swap rates be equal. Some
swap patterns could generate correlations in positions that
would not be very random.
-- glen