io.virtdata.libbasics.shared.from_long.to_long.HashRangeScaled Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-realer Show documentation
Show all versions of virtdata-lib-realer Show documentation
With inspiration from other libraries
package io.virtdata.libbasics.shared.from_long.to_long;
import io.virtdata.annotations.ThreadSafeMapper;
import java.util.function.LongUnaryOperator;
/**
* Return a pseudo-random value which can only be as large as the input.
*/
@ThreadSafeMapper
public class HashRangeScaled implements LongUnaryOperator {
private Hash hash = new Hash();
public HashRangeScaled() {
}
@Override
public long applyAsLong(long operand) {
if (operand==0) { return 0; }
long hashed = hash.applyAsLong(operand);
return hashed % operand;
}
}