JRandomArray

A package for producing pseudo random numbers via Java

Preliminaries

This package requires colt.jar and JRandomArray.class. You will need to modify the line

AddToClassPath["d:/data/packages/java"]

in JRandomArray.m to reflect the directory where you place colt.jar and JRandomArray.class.

Arrays of (10^6) random numbers can be handled with the default settings for InstallJava[]. However, in order to get an array of (10^7) random numbers you will need to use

InstallJava[CommandLine->"java -Xmx200m"]

which increases the maximum memory allocated to Java to 200MB (from its default of 60MB). Note: If InstallJava has already been invoked in the current kernel session, then later invocations have no effect. In this case you will have to UninstallJava[] first (which might break some other code). One way to implement this is to edit the file JRandomArray.m. Another way to to load JLink and invoke InstallJava prior to loading JRandomArray.

Needs["JLink`"]
InstallJava[CommandLine->"java -Xmx200m"]
<<JRandomArray`

Usage

<<JRandomArray`

Usage notes

?SeedRandomEngine

?InitializeDistribution

?JRandomArray

?RandomEngineClass

?DistributionClass

Usage

Create an instance of the 64 bit Mersenne Twister engine.

engineObj=SeedRandomEngine["MersenneTwister64"]

Create instances of uniform (0,1) and normal (0,1) distributions using the Twister engine

uniformObj=InitializeDistribution["Uniform",engineObj][0,1]
normalObj=InitializeDistribution["Normal",engineObj][0,1]

Generate a single random number:

normalObj@nextDouble[]

uniformObj@nextDouble[]

However, generating a long list is not efficient:

Table[normalObj@nextDouble[],{(10^3)}];//AbsoluteTiming

By contrast, JRandomArray is quite efficient:

JRandomArray[normalObj,(10^3)];//AbsoluteTiming

Generate an array of random numbers

JRandomArray[uniformObj,10]

JRandomArray[normalObj,10]

Methods exist to override the distribution parameter values used to construct the distribution objects:

normalObj@nextDouble[0,100]

uniformObj@nextDoubleFromTo[-100,100]

However, this facility is not implemented in JRandomArray, which only calls the default method nextDouble[] or nextInt[] for the distribution. Consequently, one must create a new instance of the distribution object using the new parameter values in order to produce a list of random numbers using JRandomArray:

normalObj10=InitializeDistribution["Normal",engineObj][0,100]

JRandomArray[normalObj10,{10,2}]