Java Doc By Examples | |

Prev Class | Next Class | Frames | No Frames |

Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |

`java.lang.Object`

`java.util.Random`

**Implemented Interfaces:**- Serializable

**Known Direct Subclasses:**- JDKRandomGenerator, JVMRandom, RandomAdaptor, SecureRandom

An instance of this class is used to generate a stream of
pseudorandom numbers. The class uses a 48-bit seed, which is
modified using a linear congruential formula. (See Donald Knuth,
*The Art of Computer Programming, Volume 2*, Section 3.2.1.)

If two instances of `Random`

are created with the same
seed, and the same sequence of method calls is made for each, they
will generate and return identical sequences of numbers. In order to
guarantee this property, particular algorithms are specified for the
class `Random`. Java implementations must use all the algorithms
shown here for the class `Random`, for the sake of absolute
portability of Java code. However, subclasses of class `Random`
are permitted to use other algorithms, so long as they adhere to the
general contracts for all the methods.

The algorithms implemented by class `Random` use a
`protected` utility method that on each invocation can supply
up to 32 pseudorandomly generated bits.

Many applications will find the `random`

method in
class `Math`

simpler to use.

**Since:**- JDK1.0

**See Also:**`Math.random()`

, Serialized Form

## Constructor Summary

`Random()`

- Creates a new random number generator.

`Random(long seed)`

- Creates a new random number generator using a single
`long`

seed:

Used by methodpublic Random(long seed) { setSeed(seed); }

`next`to hold the state of the pseudorandom number generator.

## Method Summary

`protected int`

`next(int bits)`

- Generates the next pseudorandom number.

`boolean`

`nextBoolean()`

- Returns the next pseudorandom, uniformly distributed
`boolean`

value from this random number generator's sequence.

`void`

`nextBytes(byte[] bytes)`

- Generates random bytes and places them into a user-supplied byte array.

`double`

`nextDouble()`

- Returns the next pseudorandom, uniformly distributed
`double`

value between`0.0`

and`1.0`

from this random number generator's sequence.

`float`

`nextFloat()`

- Returns the next pseudorandom, uniformly distributed
`float`

value between`0.0`

and`1.0`

from this random number generator's sequence.

`double`

`nextGaussian()`

- Returns the next pseudorandom, Gaussian ("normally") distributed
`double`

value with mean`0.0`

and standard deviation`1.0`

from this random number generator's sequence.

`int`

`nextInt()`

- Returns the next pseudorandom, uniformly distributed
`int`

value from this random number generator's sequence.

`int`

`nextInt(int n)`

- Returns a pseudorandom, uniformly distributed
`int`value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

`long`

`nextLong()`

- Returns the next pseudorandom, uniformly distributed
`long`

value from this random number generator's sequence.

`void`

`setSeed(long seed)`

- Sets the seed of this random number generator using a single
`long`

seed.

### Methods inherited from class java.lang.Object

`clone`

,`equals`

,`extends Object> getClass`

,`finalize`

,`hashCode`

,`notify`

,`notifyAll`

,`toString`

,`wait`

,`wait`

,`wait`

public Random()

Creates a new random number generator. This constructor sets the seed of the random number generator to a value very likely to be distinct from any other invocation of this constructor.

**Usages and Demos :**

View More Examples of Random()

1: { 2: publicRandom()3: { 4: ... 5: { 6: inStack.push(new Double(Math.random())); 7: return; 8: } 9: }

View Full Code Here

1: public String getPassWordKey(User user) { 2: String key = Digest.getDigest(Integer.toString((newRandom()).nextInt())); 3: authKeys.put(key, user); 4: return key; 5: }

View Full Code Here

1: 2: private int _counter = (newRandom()).nextInt(); 3: private static final String _LOB_PREFIX = "LOB"; 4: private static final String _LOB_SUFFIX = ".lob";

View Full Code Here

public Random(long seed)

Creates a new random number generator using a single`long`

seed:Used by methodpublic Random(long seed) { setSeed(seed); }nextto hold the state of the pseudorandom number generator.

Parameters:`seed`

- the initial seed.

See Also:`setSeed(long)`

**Usages and Demos :**

View More Examples of Random(long seed)

1: { 2: Random initializer = newRandom(1); 3: LifeDisplayWindow reducer = new LifeDisplayWindow(SurfaceSize, 4: SurfaceSize) ;

View Full Code Here

1: 2: private final Random random = newRandom(0); 3: 4: public FiniteRandomValueGenerator(FiniteValues values) { 5: this.values = values;

View Full Code Here

1: { 2: private Random r = newRandom(0); 3: 4: public SlowInputStream(InputStream in) { 5: super(in);

View Full Code Here

protected int next(int bits)

Generates the next pseudorandom number. Subclass should override this, as this is used by all other methods.The general contract of

nextis that it returns anintvalue and if the argument bits is between1and32(inclusive), then that many low-order bits of the returned value will be (approximately) independently chosen bit values, each of which is (approximately) equally likely to be0or1. The methodnextis implemented by classRandomas follows:This is a linear congruential pseudorandom number generator, as defined by D. H. Lehmer and described by Donald E. Knuth insynchronized protected int next(int bits) { seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1); return (int)(seed >>> (48 - bits)); }The Art of Computer Programming,Volume 2:Seminumerical Algorithms, section 3.2.1.

Parameters:`bits`

- random bits

Returns:- the next pseudorandom value from this random number generator's sequence.

Since:- JDK1.1

public boolean nextBoolean()

Returns the next pseudorandom, uniformly distributed`boolean`

value from this random number generator's sequence. The general contract ofnextBooleanis that onebooleanvalue is pseudorandomly generated and returned. The values`true`

and`false`

are produced with (approximately) equal probability. The methodnextBooleanis implemented by classRandomas follows:public boolean nextBoolean() {return next(1) != 0;}

Returns:- the next pseudorandom, uniformly distributed
`boolean`

value from this random number generator's sequence.

Since:- 1.2

**Usages and Demos :**

View More Examples of nextBoolean()

1: public class RandomGenerator { 2: private staticRandomr = newRandom(47); 3: public static class 4: ... 5: public java.lang.Boolean next() { 6: return r.nextBoolean(); 7: } 8: } 9: public static class

View Full Code Here

1: 2: import java.util.Random;3: import net.i2p.I2PAppContext; 4: ... 5: _pool[i] = new DummyRandomSource(context); 6: _pool[i].nextBoolean(); 7: } 8: ... 9: private class DummyRandomSource extends RandomSource { 10: privateRandom_prng; 11: public DummyRandomSource(I2PAppContext context) { 12: ... 13: super(context); 14: _prng = newRandom();

View Full Code Here

1: 2: import java.util.Random;3: 4: ... 5: public class RandomUtils { 6: public static finalRandomRANDOM = newRandom(System.currentTimeMillis() ); 7: 8: ... 9: { 10: return RANDOM.nextBoolean()? -1:1; 11: }

View Full Code Here

1: package de.uniwue.ki.util.math; 2: import java.util.Random;3: 4: ... 5: public final class RandomDistributionHelper implements IRandomWrapper { 6: private finalRandom_random; 7: 8: ... 9: public RandomDistributionHelper(Randomrandom) { 10: super(); 11: ... 12: public synchronized boolean nextBoolean() { 13: return _random.nextBoolean();

View Full Code Here

}

private static**Random **r = new **Random(**);

public static class RandBooleanGenerator

...

public boolean next() {

return r.**nextBoolean()**;

}

}

public static class RandByteGenerator

View Full Code Here

private static

public static class RandBooleanGenerator

...

public boolean next() {

return r.

}

}

public static class RandByteGenerator

View Full Code Here

public void nextBytes(byte[] bytes)

Generates random bytes and places them into a user-supplied byte array. The number of random bytes produced is equal to the length of the byte array.

Parameters:`bytes`

- the non-null byte array in which to put the random bytes.

Since:- JDK1.1

**Usages and Demos :**

View More Examples of nextBytes(byte[] bytes)

1: import java.util.Random; 2: import java.util.Arrays ; 3: ... 4: long seed = System.currentTimeMillis() ; 5:Randomrand = newRandom(seed) ; 6: 7: 8: for (int iter = 0 ; iter < ITERS ; iter++)

View Full Code Here

1: 2: import java.util.Random;3: import java.util.Arrays; 4: ... 5: { 6: privateRandom_r = null; 7: 8: ... 9: protected void setUp() { 10: _r = newRandom(); 11: } 12: ... 13: byte[] _orig1024 = new byte[1024]; 14: _r.nextBytes(_orig1024);

View Full Code Here

1: try { 2:Random_r = newRandom(); 3: 4: ... 5: byte[] _orig1024 = new byte[1024]; 6: _r.nextBytes(_orig1024); 7: 8: ... 9: byte[] _orig2048 = new byte[2048]; 10: _r.nextBytes(_orig2048); 11: 12: ... 13: byte[] _orig4096 = new byte[4096]; 14: _r.nextBytes(_orig4096);

View Full Code Here

1: import java.util.Arrays; 2: import java.util.Random;3: 4: ... 5: 6: private static finalRandomGENERATOR = newRandom(); 7: 8: ... 9: static { 10: GENERATOR.nextBytes(RANDOM_PAD); 11: } 12: ... 13: byte[] messageId = new byte[LENGTH]; 14: GENERATOR.nextBytes(messageId);

View Full Code Here

1: import java.security.interfaces.RSAKey; 2: import java.util.Random;3: 4: ... 5: final byte[] PS = new byte[k - M.length - 3]; 6: prng.nextBytes(PS); 7: int i = 0; 8: ... 9: 10: public byte[] encode(final byte[] M, finalRandomrnd) 11: { 12: ... 13: final byte[] PS = new byte[k - M.length - 3]; 14: rnd.nextBytes(PS);

View Full Code Here

public double nextDouble()

Returns the next pseudorandom, uniformly distributed`double`

value between`0.0`

and`1.0`

from this random number generator's sequence.The general contract of

nextDoubleis that onedoublevalue, chosen (approximately) uniformly from the range0.0d(inclusive) to1.0d(exclusive), is pseudorandomly generated and returned. All 2^{53}possiblefloatvalues of the formm x2^{-53}, wheremis a positive integer less than 2^{53}, are produced with (approximately) equal probability. The methodnextDoubleis implemented by classRandomas follows:public double nextDouble() { return (((long)next(26) << 27) + next(27)) / (double)(1L << 53); }The hedge "approximately" is used in the foregoing description only because the

nextmethod is only approximately an unbiased source of independently chosen bits. If it were a perfect source or randomly chosen bits, then the algorithm shown would choosedoublevalues from the stated range with perfect uniformity.[In early versions of Java, the result was incorrectly calculated as:

This might seem to be equivalent, if not better, but in fact it introduced a large nonuniformity because of the bias in the rounding of floating-point numbers: it was three times as likely that the low-order bit of the significand would be 0 than that it would be 1! This nonuniformity probably doesn't matter much in practice, but we strive for perfection.]return (((long)next(27) << 27) + next(27)) / (double)(1L << 54);

Returns:- the next pseudorandom, uniformly distributed
`double`

value between`0.0`

and`1.0`

from this random number generator's sequence.

**Usages and Demos :**

View More Examples of nextDouble()

1: public class RandomDoubles { 2: private staticRandomrand = newRandom(47); 3: ... 4: public double next() { return rand.nextDouble(); } 5: public static void main(String[] args) { 6: RandomDoubles rd = new RandomDoubles(); 7: for(int i = 0; i < 7; i ++)

View Full Code Here

1: package org.apache.commons.math.random;2: ... 3: import java.util.Random;4: 5: ... 6: private static final long serialVersionUID = -9161426374178114548L; 7: privateRandomrandom = newRandom(); 8: 9: ... 10: public double nextDouble() { 11: return random.nextDouble();

View Full Code Here

1: 2: import java.util.Random;3: import net.i2p.I2PAppContext; 4: ... 5: private class DummyRandomSource extends RandomSource { 6: privateRandom_prng; 7: public DummyRandomSource(I2PAppContext context) { 8: ... 9: super(context); 10: _prng = newRandom(); 11: } 12: ... 13: public void nextBytes(byte buf[]) { _prng.nextBytes(buf); } 14: public double nextDouble() { return _prng.nextDouble(); }

View Full Code Here

1: 2: import java.util.Random;3: 4: ... 5: 6: private finalRandomrandom = newRandom(0); 7: 8: ... 9: private boolean getRandom(double probability) { 10: return random.nextDouble()< probability; 11: }

View Full Code Here

1: 2: import java.util.Random;3: import javax.vecmath.Point3d; 4: ... 5: public void testFit() { 6: finalRandomrd = newRandom(457821698762354L); 7: final Plane plan = new Plane(); 8: ... 9: final Point3d P1 = new Point3d(100*rd.nextDouble()+25, 100*rd.nextDouble()+25, Math.rint(100*rd.nextDouble()+40)); 10: ... 11: final Point3d P2 = new Point3d(100*rd.nextDouble()+25, 100*rd.nextDouble()+25, Math.rint(100*rd.nextDouble()+40));

View Full Code Here

public float nextFloat()

Returns the next pseudorandom, uniformly distributed`float`

value between`0.0`

and`1.0`

from this random number generator's sequence.The general contract of

nextFloatis that onefloatvalue, chosen (approximately) uniformly from the range0.0f(inclusive) to1.0f(exclusive), is pseudorandomly generated and returned. All 2^{24}possiblefloatvalues of the formm x2^{-24}, wheremis a positive integer less than 2^{24}, are produced with (approximately) equal probability. The methodnextFloatis implemented by classRandomas follows:The hedge "approximately" is used in the foregoing description only because the next method is only approximately an unbiased source of independently chosen bits. If it were a perfect source or randomly chosen bits, then the algorithm shown would choosepublic float nextFloat() { return next(24) / ((float)(1 << 24)); }floatvalues from the stated range with perfect uniformity.[In early versions of Java, the result was incorrectly calculated as:

This might seem to be equivalent, if not better, but in fact it introduced a slight nonuniformity because of the bias in the rounding of floating-point numbers: it was slightly more likely that the low-order bit of the significand would be 0 than that it would be 1.]return next(30) / ((float)(1 << 30));

Returns:- the next pseudorandom, uniformly distributed
`float`

value between`0.0`

and`1.0`

from this random number generator's sequence.

**Usages and Demos :**

View More Examples of nextFloat()

1: import org.ariane.net.NetHost; 2: import java.util.Random;3: import org.omg.PortableServer.POA; 4: ... 5: 6: privateRandomgenerator; 7: static private POA poa = null; 8: ... 9: super(); 10: generator = newRandom(); 11: this.poa = poa; 12: ... 13: nbr++; 14: return generator.nextFloat();

View Full Code Here

1: import java.util.Iterator; 2: import java.util.Random;3: 4: ... 5: final PLayer layer = getLayer(); 6:Randomr = newRandom(); 7: for (int i = 0; i < 1000; i++) { 8: ... 9: final PNode n = PPath.createRectangle(0, 0, 100, 80); 10: n.translate(10000 * r.nextFloat(), 10000 * r.nextFloat()); 11: ... 12: n.setPaint(new Color(r.nextFloat(), r.nextFloat(),r.nextFloat()));

View Full Code Here

1: 2: import java.util.Random;3: import net.i2p.I2PAppContext; 4: ... 5: private class DummyRandomSource extends RandomSource { 6: privateRandom_prng; 7: public DummyRandomSource(I2PAppContext context) { 8: ... 9: super(context); 10: _prng = newRandom(); 11: } 12: ... 13: public double nextDouble() { return _prng.nextDouble(); } 14: public float nextFloat() { return _prng.nextFloat(); }

View Full Code Here

public double nextGaussian()

Returns the next pseudorandom, Gaussian ("normally") distributed`double`

value with mean`0.0`

and standard deviation`1.0`

from this random number generator's sequence.The general contract of

nextGaussianis that onedoublevalue, chosen from (approximately) the usual normal distribution with mean0.0and standard deviation1.0, is pseudorandomly generated and returned. The methodnextGaussianis implemented by classRandomas follows:This uses thesynchronized public double nextGaussian() { if (haveNextNextGaussian) { haveNextNextGaussian = false; return nextNextGaussian; } else { double v1, v2, s; do { v1 = 2 * nextDouble() - 1; // between -1.0 and 1.0 v2 = 2 * nextDouble() - 1; // between -1.0 and 1.0 s = v1 * v1 + v2 * v2; } while (s >= 1 || s == 0); double multiplier = Math.sqrt(-2 * Math.log(s)/s); nextNextGaussian = v2 * multiplier; haveNextNextGaussian = true; return v1 * multiplier; } }polar methodof G. E. P. Box, M. E. Muller, and G. Marsaglia, as described by Donald E. Knuth inThe Art of Computer Programming, Volume 2:Seminumerical Algorithms, section 3.4.1, subsection C, algorithm P. Note that it generates two independent values at the cost of only one call toMath.logand one call toMath.sqrt.

Returns:- the next pseudorandom, Gaussian ("normally") distributed
`double`

value with mean`0.0`

and standard deviation`1.0`

from this random number generator's sequence.

**Usages and Demos :**

View More Examples of nextGaussian()

1: 2: import java.util.Random;3: 4: ... 5: 6:Randomr = newRandom(); 7: for (int i = 0; i < 10000; i++) { 8: ... 9: lr.report(Math.round((r.nextGaussian()* 20 + 80))); 10: Thread.sleep(15);

View Full Code Here

1: public double price(String s) throws NotFound { 2:Randomrnd = newRandom(); 3: for (String t: prices.keySet()) 4: ... 5: if (t.equals(s)) 6: return prices.get(t) + 1.5*(rnd.nextGaussian()); 7: throw new NotFound(s); 8: } 9: public String[] shares() {

View Full Code Here

1: 2: import java.util.Random;3: import java.util.concurrent.TimeUnit; 4: ... 5: "my.app:name=PacketObserver"); 6:Randomr = newRandom(); 7: for (int i = 0; i < 10000; i++) { 8: ... 9: lr.report(Math.round((r.nextGaussian()* 256 + 2048))); 10: ... 11: Thread.sleep((long) Math.abs(r.nextGaussian()* 15));

View Full Code Here

1: import hep.aida.*; 2: import java.util.Random;3: 4: ... 5: 6:Randomr = newRandom(); 7: int events = 100; 8: ... 9: for ( int j = 0; j<tracks; j++ ) { 10: momentum.fill(0,r.nextGaussian()); 11: ... 12: momentum.fill(1,r.nextGaussian());

View Full Code Here

1: 2: import java.util.Random;3: import net.i2p.I2PAppContext; 4: ... 5: private class DummyRandomSource extends RandomSource { 6: privateRandom_prng; 7: public DummyRandomSource(I2PAppContext context) { 8: ... 9: super(context); 10: _prng = newRandom(); 11: } 12: ... 13: public float nextFloat() { return _prng.nextFloat(); } 14: public double nextGaussian() { return _prng.nextGaussian(); }

View Full Code Here

public int nextInt()

Returns the next pseudorandom, uniformly distributed`int`

value from this random number generator's sequence. The general contract ofnextIntis that oneintvalue is pseudorandomly generated and returned. All 2^{32 }possibleintvalues are produced with (approximately) equal probability. The methodnextIntis implemented by classRandomas follows:public int nextInt() { return next(32); }

Returns:- the next pseudorandom, uniformly distributed
`int`

value from this random number generator's sequence.

**Usages and Demos :**

View More Examples of nextInt()

1: public static void main(String[] args) { 2:Randomrand = newRandom(); 3: int i, j, k; 4: ... 5: j = rand.nextInt()% 100; 6: ... 7: k = rand.nextInt()% 100; 8: pInt("j",j); pInt("k",k);

View Full Code Here

1: import java.io.*; 2: import java.util.Random;3: import java.util.Vector; 4: ... 5: 6: private staticRandomrand = newRandom(); 7: private static Vector words; 8: ... 9: private int randInt() { 10: return rand.nextInt()& 0x7fffffff; 11: }

View Full Code Here

1: 2: import java.util.Random;3: import net.i2p.I2PAppContext; 4: ... 5: private class DummyRandomSource extends RandomSource { 6: privateRandomRandom(); 11: } 12: ... 13: public double nextGaussian() { return _prng.nextGaussian(); } 14: public int nextInt() { return _prng.nextInt(); }

View Full Code Here

public int nextInt(int n)

Returns a pseudorandom, uniformly distributedintvalue between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract ofnextIntis that oneintvalue in the specified range is pseudorandomly generated and returned. Allnpossibleintvalues are produced with (approximately) equal probability. The methodnextInt(int n)is implemented by classRandomas follows:public int nextInt(int n) { if (n<=0) throw new IllegalArgumentException("n must be positive"); if ((n & -n) == n) // i.e., n is a power of 2 return (int)((n * (long)next(31)) >> 31); int bits, val; do { bits = next(31); val = bits % n; } while(bits - val + (n-1) <320); return val; }The hedge "approximately" is used in the foregoing description only because the next method is only approximately an unbiased source of independently chosen bits. If it were a perfect source of randomly chosen bits, then the algorithm shown would choose

intvalues from the stated range with perfect uniformity.The algorithm is slightly tricky. It rejects values that would result in an uneven distribution (due to the fact that 2^31 is not divisible by n). The probability of a value being rejected depends on n. The worst case is n=2^30+1, for which the probability of a reject is 1/2, and the expected number of iterations before the loop terminates is 2.

The algorithm treats the case where n is a power of two specially: it returns the correct number of high-order bits from the underlying pseudo-random number generator. In the absence of special treatment, the correct number of

low-orderbits would be returned. Linear congruential pseudo-random number generators such as the one implemented by this class are known to have short periods in the sequence of values of their low-order bits. Thus, this special case greatly increases the length of the sequence of values returned by successive calls to this method if n is a small power of two.

Parameters:`n`

- the bound on the random number to be returned. Must be positive.

Returns:- a pseudorandom, uniformly distributed
intvalue between 0 (inclusive) and n (exclusive).

Throws:`IllegalArgumentException`

- n is not positive.

Since:- 1.2

**Usages and Demos :**

View More Examples of nextInt(int n)

1: 2: import java.util.Random;3: import javax.ejb.Stateless; 4: ... 5: public int play() { 6:Randomrandom = newRandom(); 7: ... 8: return random.nextInt(10); 9: }

View Full Code Here

1: new ThreadLocal<Integer>() { 2: privateRandomrand = newRandom(47); 3: protected synchronized Integer initialValue() { 4: ... 5: return rand.nextInt(10000); 6: } 7: }; 8: public static void increment() {

View Full Code Here

1: import org.kde.qt.*; 2: import java.util.Random;3: 4: ... 5: private QColor[] colors = new QColor[numColors]; 6: privateRandomgenerator = newRandom(System.currentTimeMillis()); 7: 8: ... 9: for (int a=0; a<numColors; a++) { 10: colors[a] = new QColor( generator.nextInt(255), 11: ... 12: generator.nextInt(255),

View Full Code Here

1: import java.util.HashSet; 2: import java.util.Random;3: import java.util.StringTokenizer; 4: ... 5: private static Generator instance; 6: privateRandomrandom = newRandom(); 7: private HashSet identifiers = new HashSet(); 8: ... 9: public boolean getBoolean(int percent) { 10: return random.nextInt(100)<= percent; 11: } 12: ... 13: public int getInt(int max) { 14: return max==0 ? 0 : random.nextInt(max);

View Full Code Here

1: 2: import java.util.Random;3: 4: ... 5: public class TestDocSet extends TestCase { 6:Randomrand = newRandom(); 7: 8: ... 9: for (int i=0; i<bitsToSet; i++) { 10: bs.fastSet(rand.nextInt(sz)); 11: } 12: ... 13: public DocSet getDocSet(OpenBitSet bs) { 14: return rand.nextInt(2)==0 ? getHashDocSet(bs) : getBitDocSet(bs);

View Full Code Here

public long nextLong()

Returns the next pseudorandom, uniformly distributed`long`

value from this random number generator's sequence. The general contract ofnextLongis that one long value is pseudorandomly generated and returned. All 2^{64}possiblelongvalues are produced with (approximately) equal probability. The methodnextLongis implemented by classRandomas follows:public long nextLong() { return ((long)next(32) << 32) + next(32); }

Returns:- the next pseudorandom, uniformly distributed
`long`

value from this random number generator's sequence.

**Usages and Demos :**

View More Examples of nextLong()

1: public static void main(String[] args) { 2:Randomrand = newRandom(47); 3: int i = rand.nextInt(); 4: ... 5: 6: long l = rand.nextLong(); 7: ... 8: long m = rand.nextLong(); 9: printBinaryLong("-1L", -1L);

View Full Code Here

1: 2: import java.util.Random;3: import net.i2p.I2PAppContext; 4: ... 5: private class DummyRandomSource extends RandomSource { 6: privateRandomRandom(); 11: } 12: ... 13: public long nextLong(long n) { 14: long v = _prng.nextLong();

View Full Code Here

1: import java.io.Serializable; 2: import java.util.Random;3: 4: ... 5: protected Object mHandback; 6: privateRandommRandom = newRandom(); 7: 8: ... 9: try { 10: lName = new ObjectName( "JMX:type=listener,id=" + mRandom.nextLong()); 11: ObjectInstance lInstance = pConnector.createMBean(

View Full Code Here

1: import java.rmi.RemoteException; 2: import java.util.Random;3: 4: ... 5: protected Object mHandback; 6: privateRandommRandom = newRandom(); 7: 8: ... 9: { 10: lName = new ObjectName("JMX:type=listener,id=" + mRandom.nextLong()); 11: ObjectInstance lInstance = pConnector.createMBean(

View Full Code Here

public void setSeed(long seed)

Sets the seed of this random number generator using a single`long`

seed. The general contract ofsetSeedis that it alters the state of this random number generator object so as to be in exactly the same state as if it had just been created with the argumentseedas a seed. The methodsetSeedis implemented by class Random as follows:The implementation ofsynchronized public void setSeed(long seed) { this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1); haveNextNextGaussian = false; }setSeedby classRandomhappens to use only 48 bits of the given seed. In general, however, an overriding method may use all 64 bits of the long argument as a seed value. Note: Although the seed value is an AtomicLong, this method must still be synchronized to ensure correct semantics of haveNextNextGaussian.

Parameters:`seed`

- the initial seed.

**Usages and Demos :**

View More Examples of setSeed(long seed)

1: package org.apache.commons.math.random;2: import junit.framework.Test; 3: ... 4: import junit.framework.TestSuite; 5: import java.util.Random;6: 7: ... 8: ConstantGenerator generator = new ConstantGenerator(); 9:Randomrandom = RandomAdaptor.createAdaptor(generator); 10: checkConstant(random); 11: ... 12: assertEquals(0, random.nextLong()); 13: random.setSeed(100);

View Full Code Here

1: 2: import java.util.Random;3: import java.util.Arrays; 4: ... 5: long currentTime = System.currentTimeMillis() * 10 + 0x01B21DD213814000L; 6:RandomrandomGen = newRandom(); 7: ... 8: randomGen.setSeed(((currentTime >> 32)^ currentTime) & 0xffffffffL); 9: ourUUIDStateSeqNum = randomGen.nextLong() & 0x0FFFFL;

View Full Code Here

1: import java.awt.*; 2: import java.util.Random;3: public class PercolationApp extends AbstractCalculation 4: ... 5: int NONE = -99, selectedCluster = NONE; 6:Randomrandom; 7: 8: ... 9: { 10: random.setSeed(1239012312); 11: L = control.getInt("L");

View Full Code Here

1: import java.util.ConcurrentModificationException; 2: import java.util.Random;3: 4: ... 5: 6: private finalRandomrandom = newRandom(0); 7: 8: ... 9: super.paintComponent(g); 10: random.setSeed(0); 11: try {

View Full Code Here

1: 2: import java.util.Random;3: 4: ... 5: static final int POW = 13; 6: static final intRANDOM= 14; 7: static final int ROUND = 15; 8: ... 9: put(math, "tan", TAN, 1); 10: put(math, "random",RANDOM,0); 11: put(math, "setSeed", SET_SEED, 1); 12: ... 13: if (length != 0) 14: random.setSeed((long)eval.getArg(0).toNum());

View Full Code Here