On 13/06/2019 17:56, Eric Barnhill wrote:
On Thu, Jun 13, 2019 at 9:36 AM sebb <seb...@gmail.com> wrote:
Rather than shuffle etc in place, how about various
iterators/selectors to return entries in randomised order?
[Or does that already exist?]
I am pretty sure random draws, and shuffling, are implemented with
different algorithms. Though sampling without replacement the full length
of the set would yield a shuffled set, I think there are more efficient
ways to shuffle a set.
Iterators to return a random draw *without* replacement over the full
length of the array? The iterator would dynamically shuffle the array on
each call to next() so could be stopped early or can be called
infinitely as if a continuous stream. Is that your idea?
UniformRandomProvider rng = ...;
int[] big = new int[1000000];
//
// Fill big with lots of data
//
IntIterator iter = ShuffleIterators.create(rng, big);
int x = iter.next();
int y = iter.next();
int z = iter.next();
This doesn't exist but it is easy to do. Memory requirements would
require a copy of the data, or it could be marked as destructive to the
input array order and shuffle in place.
If you want a random draw *with* replacement then you can just call
nextInt(int) with the size of the array to pick something.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org