Random numbers
Author(s): Daniel Cabeza.
This module provides predicates for generating pseudo-random numbers
Usage and interface
- Library usage:
:- use_module(library(random)). - Exports:
- Imports:
- System library modules:
foreign_interface/foreign_interface_properties. - Packages:
prelude, nonpure, assertions, isomodes, foreign_interface, basicmodes, regtypes, foreign_interface(foreign_interface_ttrs), foreign_interface(foreign_interface_ops).
- System library modules:
Documentation on exports
PREDICATE
random(Number)
Number is a (pseudo-) random number in the range [0.0,1.0]
(True) 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]
(True) Usage 1:
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.
(True) 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.
(True) 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).
(True) 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.