Random numbers

Author(s): Daniel Cabeza.

This module provides predicates for generating pseudo-random numbers

Usage and interface

Documentation on exports

PREDICATE
random(Number)

Number is a (pseudo-) random number in the range [0.0,1.0]

Usage:

  • The following properties should hold at call time:
    (term_typing:var/1)Number is a free variable.
  • The following properties hold upon exit:
    (term_typing:float/1)Number is currently instantiated to a float.
  • The following properties hold globally:
    (foreign_interface_properties:foreign_low/2)The Prolog predicate PrologName is implemented using the function ForeignName. The same considerations as above example are to be applied.

PREDICATE
random(Low,Up,Number)

Number is a (pseudo-) random number in the range [Low, Up]

Usage 1:

  • Description: If Low and Up are integers, Number is an integer.
  • The following properties should hold at call time:
    (basic_props:int/1)Low is an integer.
    (basic_props:int/1)Up is an integer.
    (term_typing:var/1)Number is a free variable.
  • The following properties hold upon exit:
    (basic_props:int/1)Number is an integer.
  • The following properties hold globally:
    (foreign_interface_properties:foreign_low/2)The Prolog predicate PrologName is implemented using the function ForeignName. The same considerations as above example are to be applied.

Usage 2:

  • The following properties should hold at call time:
    (basic_props:flt/1)Low is a float.
    (basic_props:num/1)Up is a number.
    (term_typing:var/1)Number is a free variable.
  • The following properties hold upon exit:
    (basic_props:flt/1)Number is a float.

Usage 3:

  • The following properties should hold at call time:
    (basic_props:int/1)Low is an integer.
    (basic_props:flt/1)Up is a float.
    (term_typing:var/1)Number is a free variable.
  • The following properties hold upon exit:
    (basic_props:flt/1)Number is a float.

PREDICATE
srandom(Seed)

Changes the sequence of pseudo-random numbers according to Seed. The stating sequence of numbers generated can be duplicated by calling the predicate with Seed unbound (the sequence depends on the OS).

Usage:

  • Calls should, and exit will be compatible with:
    (basic_props:int/1)Seed is an integer.
  • The following properties hold upon exit:
    (basic_props:int/1)Seed is an integer.
  • The following properties hold globally:
    (foreign_interface_properties:foreign_low/2)The Prolog predicate PrologName is implemented using the function ForeignName. The same considerations as above example are to be applied.