Hashing an arbitrary object to a sparse array of bits 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&lt;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 constructor
bpe is also a field, set on initialization to Math.max(5, Math.min(size/8,(int)Math.sqrt(size)))


Is there a better way to do this?
Wasting space?
I don't know if there's a better way of generating your hashed bits, but you are using 32x the amount of space that you need to.  I would suggest using all the bits in your keys array rather than just 1 bit per int.
What is l for?
One thing I don't understand about your hash is the use of l.  You are already using random numbers to generate your hash, so why do you need to add two random numbers together?  Is it supposed to generate more randomness?  I don't think it does.
An example of packing the bits
// Only allocate one int for every 32 bits.
keys = new int[(size+31)/32];
for(int i=0;i&lt;bpe;i++){
    int bitNum = (r.nextInt(size)+l)%size;
    keys[bitNum &gt;&gt; 5] |= (1 &lt;&lt; (bitNum &amp; 31));
}

To retrieve the bit, previously, you would do:
isBitSet = keys[bitNum] != 0;

Now you would do:
isBitSet = (keys[bitNum &gt;&gt; 5] &amp; (1 &lt;&lt; (bitNum &amp; 31))) != 0;