Sather Home Page

Section 8.12.1.23:
$RANDOM_GEN

abstract class $RANDOM_GEN

Formal Definitions

This abstract class defines a state component which is a set of all instantiations of objects of any class sub-typing from this class in addition to the vdm model types used wherever this class name is used. Note that SAME has to be an instantiated class, not an abstract one.

types

SAME = object_type ;
$RANDOM_GEN = set of object_type

state

references : $RANDOM_GEN
   inv ref_types ==
      forall obj | obj in set ref_types &
         sub_type($RANDOM_GEN,obj)
NOTE See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstraction models a generator of pseudo-random numbers.

create

This creation operation produces a new random number generator.

create : SAME
Formal Signature
create() res : SAME
Pre-condition

Since there are no arguments this pre-condition is vacuously true.

Post-condition

Since there are no arguments involved in creating a new generator then this post-condition is also vacuously true.

This creation operation returns a new pseudo-random number generator


init

This feature initialises the generator with an arbitrary seed provided as argument.

init (
seed : CARD
)
Formal Signature
init(self : SAME, seed : CARD)
Pre-condition

Since none of the arguments is optional then this pre-condition is vacuously true.

Post-condition

Since the value of the seed merely affects some future value provided by get, the post-condition is true.

This feature initialises the generator with the given seed.


get

This feature returns the next (pseudo-)random number in the sequence.

get : FLTD
Formal Signature
get(self : SAME) res : FLTD
Pre-condition

Since the self argument is not optional then this pre-condition is vacuously true.

Post-condition

Since the value being returned is random then the post-condition is also true providing that the number yielded conforms to the randomness requirement.

This feature returns the next random number in sequence.


Language Index Library Index Numeric Index
Comments or enquiries should be made toKeith Hopper.
Page last modified: Thursday, 31 May 2001.
Produced with Amaya