Java Code Examples for cern.jet.random.engine.MersenneTwister#nextInt()
The following examples show how to use
cern.jet.random.engine.MersenneTwister#nextInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntBloomFilter.java From database with GNU General Public License v2.0 | 6 votes |
/** Creates a new Bloom filter with given number of hash functions and expected number of elements. * * @param n the expected number of elements. * @param d the number of hash functions; if the filter add not more than <code>n</code> elements, * false positives will happen with probability 2<sup>-<var>d</var></sup>. */ public IntBloomFilter( final int n, final int d ) { this.d = d; bits = LongArrayBitVector.getInstance().length( (long)Math.ceil( ( n * d / NATURAL_LOG_OF_2 ) ) ); m = bits.length() * Long.SIZE; if ( DEBUG ) System.err.println( "Number of bits: " + m ); // The purpose of Random().nextInt() is to generate a different seed at each invocation. final MersenneTwister mersenneTwister = new MersenneTwister( new Random().nextInt() ); a = new int[ d ]; b = new int[ d ]; for( int i = 0; i < d; i++ ) { a[ i ] = mersenneTwister.nextInt(); b[ i ] = mersenneTwister.nextInt(); } }
Example 2
Source File: BloomFilter.java From database with GNU General Public License v2.0 | 6 votes |
/** Creates a new Bloom filter with given number of hash functions and expected number of elements. * * @param n the expected number of elements. * @param d the number of hash functions; under obvious uniformity and indipendence assumptions, * if the filter has not more than <code>n</code> elements, * false positives will happen with probability 2<sup>-<var>d</var></sup>. */ public BloomFilter( final int n, final int d ) { this.d = d; final long wantedNumberOfBits = (long)Math.ceil( n * ( d / NATURAL_LOG_OF_2 ) ); if ( wantedNumberOfBits > MAX_BITS ) throw new IllegalArgumentException( "The wanted number of bits (" + wantedNumberOfBits + ") is larger than " + MAX_BITS ); bits = new long[ (int)( ( wantedNumberOfBits + Long.SIZE - 1 ) / Long.SIZE ) ]; m = bits.length * (long)Long.SIZE; if ( DEBUG ) System.err.println( "Number of bits: " + m ); // The purpose of Random().nextInt() is to generate a different seed at each invocation. final MersenneTwister mersenneTwister = new MersenneTwister( new Random().nextInt() ); weight = new int[ d ][]; init = new int[ d ]; for( int i = 0; i < d; i++ ) { weight[ i ] = new int[ NUMBER_OF_WEIGHTS ]; init[ i ] = mersenneTwister.nextInt(); for( int j = 0; j < NUMBER_OF_WEIGHTS; j++ ) weight[ i ][ j ] = mersenneTwister.nextInt(); } }