Previous Up Next

8.25 Random number generator

8.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 variableinstantiation_error
Seed is neither a variable nor an integertype_error(integer, Seed)
Seed is an integer < 0domain_error(not_less_than_zero, Seed)

Portability

GNU Prolog predicates.

8.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 integertype_error(integer, Seed)
Seed is an integer < 0domain_error(not_less_than_zero, Seed)

Portability

GNU Prolog predicate.

8.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 variableuninstantiation_error(Number)

Portability

GNU Prolog predicate.

8.25.4 random/3

Templates

random(+number, +number, -number)

Description

random(Base, Max, Number) unifies Number with a random number such that BaseNumber < 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 variableinstantiation_error
Base is neither a variable nor a numbertype_error(number, Base)
Max is a variableinstantiation_error
Max is neither a variable nor a numbertype_error(number, Max)
Number is not a variableuninstantiation_error(Number)

Portability

GNU Prolog predicate.

Copyright (C) 1999-2023 Daniel Diaz 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