Previous Up Next
7.25 Random number generator

7.25.1 set_seed/1, randomize/0

Templates
set_seed(+integer)
randomize
Description

set_seed(Seed) reinitializes the random number generator seed with Seed.

randomize reinitializes the random number generator. This predicates calls set_seed/1 with a random value depending on the absolute time.

Errors
Seed is a variable    instantiation_error
Seed is neither a variable nor an integer    type_error(integer, Seed)
Seed is an integer < 0    domain_error(not_less_than_zero, Seed)

Portability

GNU Prolog predicates.

7.25.2 get_seed/1

Templates
get_seed(?integer)
Description

get_seed(Seed) unifies Seed with the current random number generator seed.

Errors
Seed is neither a variable nor an integer    type_error(integer, Seed)
Seed is an integer < 0    domain_error(not_less_than_zero, Seed)

Portability

GNU Prolog predicate.

7.25.3 random/1

Templates
random(-float)
Description

random(Number) unifies Number with a random floating point number such that 0.0 <= Number < 1.0.

Errors
Number is not a variable    type_error(variable, Number)

Portability

GNU Prolog predicate.

7.25.4 random/3

Templates
random(+number, +number, -number)
Description

random(Base, Max, Number) unifies Number with a random number such that Base <= Number < Max. If both Base and Max are integers Number will be an integer, otherwise Number will be a floating point number.

Errors
Base is a variable    instantiation_error
Base is neither a variable nor a number    type_error(number, Base)
Max is a variable    instantiation_error
Max is neither a variable nor a number    type_error(number, Max)
Number is not a variable    type_error(variable, Number)

Portability

GNU Prolog predicate.




Copyright (C) 1999-2002 Daniel Diaz.

Chapters 9 and 10 : Copyright (C) 2002-2003 INRIA, Rémy Haemmerlé.

Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.

More about the copyright
Previous Up Next