use of java.util.function.LongToIntFunction in project MindsEye by SimiaCryptus.
the class TestUtil method shuffle.
/**
* Shuffle int stream.
*
* @param stream the stream
* @return the int stream
*/
public static IntStream shuffle(@Nonnull IntStream stream) {
// http://primes.utm.edu/lists/small/10000.txt
long coprimeA = 41387;
long coprimeB = 9967;
long ringSize = coprimeA * coprimeB - 1;
@Nonnull IntToLongFunction fn = x -> (x * coprimeA * coprimeA) % ringSize;
@Nonnull LongToIntFunction inv = x -> (int) ((x * coprimeB * coprimeB) % ringSize);
@Nonnull IntUnaryOperator conditions = x -> {
assert x < ringSize;
assert x >= 0;
return x;
};
return stream.map(conditions).mapToLong(fn).sorted().mapToInt(inv);
}
Aggregations