Packagecom.yworks.bridge.util
Classpublic class Random
InheritanceRandom Inheritance YObject Inheritance Object
Subclasses YRandom

A pseudo random number generator.

Based on a fast XOR-Shift PRNG by Marsaglia, George. (2003). Xorshift RNGs. http://www.jstatsoft.org/v08/i14/xorshift.pdf



Public Properties
 PropertyDefined By
  seed : int
[write-only] Sets an int value as seed.
Random
Public Methods
 MethodDefined By
  
Random(init:Boolean = true)
Construct a random generator with the current time of day in milliseconds as the initial state.
Random
 Inherited
equals(o:Object):Boolean
YObject
  
getClass():Class
[override]
Random
 Inherited
hashCode():int
YObject
  
[static] Construct a random generator with the current time of day in milliseconds as the initial state.
Random
  
[static] Construct a random generator with the given seed as the initial state.
Random
  
nextBoolean():Boolean
Answers the next pseudo-random, uniformly distributed boolean value generated by this generator.
Random
  
nextBytes(buf:Vector.<int>):void
Modifies the byte array by a random sequence of bytes generated by this random number generator.
Random
  
nextDouble():Number
Generates a normally distributed random double number between 0.0 inclusively and 1.0 exclusively.
Random
  
nextFloat():Number
Generates a normally distributed random float number between 0.0 inclusively and 1.0 exclusively.
Random
  
nextGaussian():Number
Returns a pseudo-randomly generated, normally distributed double value with mean 0.0 and a standard deviation value of 1.0.
Random
  
nextInt():int
Generates a uniformly distributed 32-bit int value from the this random number sequence.
Random
  
nextInt2(n:int):int
Returns a new pseudo-random integer value which is uniformly distributed between 0 (inclusively) and n (exclusively).
Random
  
Generates a uniformly distributed 64-bit int value from the this random number sequence.
Random
Protected Methods
 MethodDefined By
  
Initializes this object.
Random
  
Initializes this object.
Random
  
next(bits:int):int
Returns a pseudo-random uniformly distributed int value of the number of bits specified by the argument bits.
Random
Property Detail
seedproperty
seed:int  [write-only]

Sets an int value as seed.


Implementation
    public function set seed(value:int):void

See also

Constructor Detail
Random()Constructor
public function Random(init:Boolean = true)

Construct a random generator with the current time of day in milliseconds as the initial state.

Parameters
init:Boolean (default = true) — An internally used switch to help handle proper instance initialization in inheritance chains where classes can have multiple constructor-like factory methods. This parameter can safely be ignored/omitted when calling the constructor.

See also

Method Detail
getClass()method
override public function getClass():Class

Returns
Class
initRandom1()method 
protected final function initRandom1():void

Initializes this object. See the documentation of the corresponding factory method newRandom1() for details.

See also

initRandom2()method 
protected final function initRandom2(seed:LongImpl):void

Initializes this object. See the documentation of the corresponding factory method newRandom2() for details.

Parameters

seed:LongImpl

See also

newRandom1()method 
public static function newRandom1():Random

Construct a random generator with the current time of day in milliseconds as the initial state.

Returns
Random

See also

newRandom2()method 
public static function newRandom2(seed:LongImpl):Random

Construct a random generator with the given seed as the initial state.

Parameters

seed:LongImpl — the seed that will determine the initial state of this random number generator

Returns
Random

See also

next()method 
protected function next(bits:int):int

Returns a pseudo-random uniformly distributed int value of the number of bits specified by the argument bits. Implements D. H. Lehmer's random number algorithm found in The Art of Computer Programming, Volume 2: Seminumerical Algorithms, by Donald E. Knuth (section 3.2.1).

Parameters

bits:int — number of bits of the returned value

Returns
int — a pseudo-randomly generated int

See also

nextBoolean()method 
public function nextBoolean():Boolean

Answers the next pseudo-random, uniformly distributed boolean value generated by this generator.

Returns
Boolean — boolean a pseudo-random, uniformly distributed boolean value
nextBytes()method 
public function nextBytes(buf:Vector.<int>):void

Modifies the byte array by a random sequence of bytes generated by this random number generator.

Parameters

buf:Vector.<int> — non-null array to contain the new random bytes

See also

nextDouble()method 
public function nextDouble():Number

Generates a normally distributed random double number between 0.0 inclusively and 1.0 exclusively.

Returns
Number — a random double between 0.0 and 1.0

See also

nextFloat()method 
public function nextFloat():Number

Generates a normally distributed random float number between 0.0 inclusively and 1.0 exclusively.

Returns
Number — a random float between 0.0 and 1.0

See also

nextGaussian()method 
public function nextGaussian():Number

Returns a pseudo-randomly generated, normally distributed double value with mean 0.0 and a standard deviation value of 1.0. Implements G. E. P. Box, M. E. Muller, and G. Marsaglia's polar method found in The Art of Computer Programming, Volume 2: Seminumerical Algorithms, by Donald E. Knuth (section 3.4.1).

Returns
Number — a pseudo-randomly generated double

See also

nextInt()method 
public function nextInt():int

Generates a uniformly distributed 32-bit int value from the this random number sequence.

Returns
int — a randomly generated int

See also

int.MAX_VALUE
int.MIN_VALUE
next()
nextLong()
nextInt2()method 
public function nextInt2(n:int):int

Returns a new pseudo-random integer value which is uniformly distributed between 0 (inclusively) and n (exclusively).

Parameters

n:int — the upper limit of the values that can be returned

Returns
int — a randomly generated int between 0 and n
nextLong()method 
public function nextLong():LongImpl

Generates a uniformly distributed 64-bit int value from the this random number sequence.

Returns
LongImpl — 64-bit int random number

See also

int.MAX_VALUE
int.MIN_VALUE
next()
nextInt()
nextInt2()