Abstract

The quality and representativeness
of simulation results heavily depend on the sequence of numbers used in the
experiments. When dealing with simulations
of critical systems, it might be necessary to increase the representativeness of
such results by running experiments with different sequences and to investigate
the system behaviour in specific situations. jRand increases the
flexibility in the configuration of the input sequences and that raises the simulation
system developers from their details while designing and coding simulation
software. Using jRand, simulation system developers are raised from the
concerns of the choice of sequences, which can in turn be designed and applied with less
effort for the specific scenarios.

**jRand**

**jRand** is a Java component-based
framework for sequences of objects, which particularly addresses numbers, that allows the
implementation of sources of number with generic properties (e.g. deterministic,
stochastic with random or pseudo-random predictability).jRand structure bases
on the concept of object producer and object consumers, which decouples the components
providing objects from the ones using them. Object producers are identified by
the base interface *ObjectStream*. They can be of various types, such as
hand-typed numbers from file, hard-coded in the software, or internally generated
by functions. The object consumers, which use the interface ObjectStream, are
not concerned with the details of the sequence generation, and therefore
sequences can be transparently interchanged without modifying their code.

**Structure of the framework**

The structure of the
framework is illustrated in Figure 1 with the use of UML class diagram.

Figure 1: Class diagram of
jRand

Its definition bases on the interface *ObjectStream*. The interface defines service
specifications for object producers, which have to provide two services: *getNextObject()* and *goToObject(n)*. Where the former returns the next object in the stream
and the latter shifts the stream of *n* positions.

On top of the general object producer
interface, jRand defines several groups of sequences according to the
properties they can have. Currently, jRand categorizes the sequences according
to three criterions, which might overlap though. The first one *(a)* is related to the *dependences between values in a sequence*;
the second one *(b)* concerns *the type of values*; and the third *(c)* considers *the structural details of the objects producers*, and therefore a
selected object stream can be identified as holding one or more of the above
properties.

According to the property (a), sequences of
objects can be classified in three types

- Random
- Pseudo-Random
- Deterministic

Each of which classifies the sequences
according to the statistical relationship between adjacent objects in the
sequence in terms of bit-wise comparison.

*Random* tags all those streams that present a purely random sequence, which
is thus not reproducible. Typically, streams of
this group rely on the number of nanoseconds measured by the system clock or
the unpredictable values contained in sets of address in the local physical memory. For their properties, such type of stream is to be
avoided in systematic simulation experiments since the reproducibility of the
runs is not guaranteed.

*Pseudo-Random* stands for the stream for which it is expected that the objects
present statistical properties such as uniformity and serial correlation, even
though they are deterministically generated. This type of sequence might have
input parameters that can vary the sequence and can be statistically tested to
assess their goodness in terms of the above statistical properties.

*Deterministic* represents the streams for which the sequence is known completely
and explicitly since of the producer definition. By definition, a deterministic
stream presents always the same sequence of objects and has no input parameters.

Although the above classification might lead
to an ambiguous categorization of object streams, such uncertainty can be
easily resolved by considering the expected use of the sequence. For example if
we consider a hand-typed object stream residing on a file, it might belong to
either the *deterministic* or the *pseudo-random* group. The stream creator
will determine which the scope of the stream is, that could be deterministic
for highly-correlated objects in the stream or could be pseudo-random if it
statically satisfies some statistical properties. Certainly, it cannot be
classified as Random since the object order is known.

The second property (b) characterizing a
stream of objects is the *type*. Object
is an abstract type, which can be subjected to general properties and general
transformation. Grouping the streams of objects according to their type
contributes to the definition of specific properties and transformations. For
example, considering Numbers as a special type of Objects, several properties
can be more formally quantified through statistical tests and more
transformations can be defined, such as algebraic transformations. We will
discuss the Numbers in the following section.

The *structural
properties* (c) of the sequence of objects are captured by the
classification according to the transformation.
Transformations group object streams that are obtained through
composition, interleaving or functional transformation of one or more object
streams by acting as decoration or composition of existing object stream. For the abstract type Object, this category defines a
base interface, which plays a marker role, and a set of classes. Possible simple
stream transformation classes are (Figure
1)
*Round Robin*, which takes n object
streams and uses the next object for each stream until all the stream are used,
and then starts over

*Repeated*, which repeats the elements of
a specified stream

Other transformations might consider the
use of stream of type Number to perform more complex operations on a set of
streams. For example:

*Shuffled Stream*, which takes one object
stream *o* and a numeric stream *n*. The shuffle maintains an array of a
certain number of objects generated by *o*
and uses *n* to select one of the
objects. When returned, each object is replaced with a new one from the stream *o*

*Stream Splitter*, which takes an object stream
*o* and a numeric stream *n*, and uses *n* to shift the object stream between each request of a new object.

**Sequence of Numbers: Numeric Stream**

*Numeric
Streams* represent the streams of Numbers. They conform
to the *ObjectStream* interface, which
is then specialized to *NumericStream*
and redefined in the return type of the method *getNextNumber()*. *NumericStream*
can be classified according to the same properties of the general object stream.
In addition, however, they present the inherent properties of numbers. Such
properties enrich the semantic of the objects and widen the set of possible
transformations.

Concerning property (a), *Numeric Streams* can be classified in *random*, *pseudo-random* and *deterministic*.
Differently from the general Object stream, however, *NumericStream* can be accurately assessed in their random and
pseudo-random properties with statistical tests, such as chi-square or serial
test.

In jRand, *pseudo-random*
numeric streams are further divided into *core
generators* and *distribution
generators*. The former group consists of uniform generators over the
available set of integers. In such group, all the linear-congruent and
multiplicative congruent generators are defined. The latter group, differently,
includes the generators that produce real numbers with specified statistical
properties, such as Exponential, Gaussian, K-Erlang, Coxian, Poisson, Truncated Pareto, Weibull, Geometric or LogNormal.

We distinguish *pseudo-random* stream in two groups because of the component-based
design of jRand. In fact, the functional transformations from which the
exponential, Gaussian, etc. generators are derived is indeed independent from
how the original integer sequences are produced. They rely on the hypothesis
that the original sequence is uniformly distributed, property which is in turn
to be assessed with statistical tests.
In the current release, jRand defines a
core generator that has already been designed and developed in The JavaSim’s User
Guide, University
of New Castel,
http:// javasim.ncl.ac.uk. Nevertheless, such contribution is complementary to
jRand, and therefore a combination of both approaches brings the advantages of
such generator with the jRand flexible structure. As suggested in "D. Knuth, The Art of
Computer Programming Vol. 2 - Seminumerical Algorithms, Addison-Wesley, US,
1969", the generator consists of a shuffled combination of
linear and multiplicative generators. The multiplicative generator is defined
through the following expression:

Y[i+1] = Y[i] * (5^{5 }mod 2^{26});

which presents a period of 2^{24} when
the initial seed is odd. The linear congruent generator, which is based on the
algorithm in "R. Sedgewick,
Algorithms, Addison-Wesley, 1983", produces numbers that are eventually shuffled by the
above multiplicative generator. In the specific context, the initial seed is set at 772531
to meet the conditions that guarantee good statistical uniformity and longest
period.

The jRand implementation of this generator is done through the object
transformations. Specifically, the shuffled stream transformation is used with
type Number and the two numeric streams of the two generators, the multiplicative
and the linear congruent, which are respectively the objects shuffler and the
object stream to shuffle.
Concerning the transformation (c), Numbers can
be subjected to a wider set of possible types. Besides shuffling or
interleaving transformation, numeric stream can also be manipulated with
standard operations on numbers. For example, a single numeric stream can be
shifted, can be multiplied, can be truncated or bounded to a range. Other
operations that combine multiple numeric streams are also possible, such as sum
or subtraction of streams. In its current version jRand provides for this group
of *NumericStream*, the following
classes: *Integerizer*, *LinearTransformation*, and *BoundedStream*, nevertheless other
transformation can be immediately coded in the framework. *Integerizer* converts a general *NumericStream*
in an integer stream; *LinearTransformation*
multiplies for and adds constant numbers to the given *NumericStream*; and finally the number *BoundedStream* limits the range of numbers of a specified *NumericStream*.

**jRand example of use**

The
instantiation of a jRand sequence inside a simulation system requires first
that a *NumericStream* interface be
defined. This can be obtained with the following statement:

#1 NumericStream
numericStream;

Then, the proper sequence has to be
instantiated. For example, in the case of a pseudo-random exponential
generator, this can be done with the following statements:

#2 CoreGenerator cg = new
JavasimGen ();

#3 numericStream = new
Exponential(cg,lambda);

Where statement #2 allocates a core
generator that produces a uniform sequence of numbers in the range [-MAX_LONG -
1; MAX_LONG], such as the JavasimGenerator. Finally, statement #3 allocates an
exponential transformation of such stream, with parameter lambda to be
specified.