I have this method in one of the java classes I'm working on (an implementation of a counting bloom filter):
private int[] hash(V v){
Random r=new Random(v.hashCode());
int l=r.nextInt(size);
int[] keys=new int[size];
for(int i=0;i<bpe;i++){
keys[(r.nextInt(size)+l)%size]=1;
}
return keys;
}
Where:
- V is one of the type parameters for the enclosing generic class
size
is a field set on initialization, defaults to 64 unless specified otherwise from the constructorbpe
is also a field, set on initialization toMath.max(5, Math.min(size/8,(int)Math.sqrt(size)))
Is there a better way to do this?