bug fices
This commit is contained in:
@@ -20,10 +20,10 @@
|
||||
* @author original code from RA O'Keefe.
|
||||
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
|
||||
* @date Wed Nov 18 00:05:21 2015
|
||||
*
|
||||
*
|
||||
* @brief Integer Random Number Generator
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
:- module(random, [
|
||||
@@ -54,13 +54,13 @@ In ROK's words: ``This is algorithm AS 183 from Applied Statistics. I also have
|
||||
|
||||
*/
|
||||
|
||||
/** @pred getrand(- _Key_)
|
||||
/** @pred getrand(- _Key_)
|
||||
|
||||
|
||||
Unify _Key_ with a term of the form `rand(X,Y,Z)` describing the
|
||||
current state of the random number generator.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ Unify _Number_ with a number in the range
|
||||
integers then _NUMBER_ will also be an integer, otherwise
|
||||
_NUMBER_ will be a floating-point number.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -85,34 +85,34 @@ The following routines produce random non-negative integers in the range
|
||||
generated by this random number generator are repeatable. This generator
|
||||
was originally written by Allen Van Gelder and is based on Knuth Vol 2.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/** @pred random(- _Number_)
|
||||
/** @pred random(- _Number_)
|
||||
|
||||
|
||||
Unify _Number_ with a floating-point number in the range `[0...1)`.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/** @pred randseq(+ _LENGTH_, + _MAX_, - _Numbers_)
|
||||
/** @pred randseq(+ _LENGTH_, + _MAX_, - _Numbers_)
|
||||
|
||||
|
||||
Unify _Numbers_ with a list of _LENGTH_ unique random integers
|
||||
in the range `[1... _MAX_)`.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/** @pred randset(+ _LENGTH_, + _MAX_, - _Numbers_)
|
||||
/** @pred randset(+ _LENGTH_, + _MAX_, - _Numbers_)
|
||||
|
||||
|
||||
Unify _Numbers_ with an ordered list of _LENGTH_ unique random
|
||||
integers in the range `[1... _MAX_)`.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/** @pred setrand(+ _Key_)
|
||||
/** @pred setrand(+ _Key_)
|
||||
|
||||
|
||||
Use a term of the form `rand(X,Y,Z)` to set a new state for the
|
||||
@@ -126,7 +126,6 @@ random number generator. The integer `X` must be in the range
|
||||
|
||||
*/
|
||||
:- use_module(library(pairs)).
|
||||
:- use_module(library(error)).
|
||||
:- use_module(library(lists)).
|
||||
|
||||
|
||||
@@ -152,25 +151,25 @@ random(L, U, R) :-
|
||||
).
|
||||
|
||||
/* There are two versions of this operation.
|
||||
|
||||
|
||||
randset(K, N, S)
|
||||
|
||||
|
||||
generates a random set of K integers in the range 1..N.
|
||||
The result is an ordered list, such as setof might produce.
|
||||
|
||||
|
||||
randseq(K, N, L)
|
||||
|
||||
|
||||
generates a random sequence of K integers, the order is as
|
||||
random as we can make it.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
randset(K, N, S) :-
|
||||
K >= 0,
|
||||
K =< N,
|
||||
randset(K, N, [], S).
|
||||
|
||||
|
||||
|
||||
|
||||
randset(0, _, S, S) :- !.
|
||||
randset(K, N, Si, So) :-
|
||||
random(X),
|
||||
@@ -181,13 +180,13 @@ randset(K, N, Si, So) :-
|
||||
randset(K, N, Si, So) :-
|
||||
M is N-1,
|
||||
randset(K, M, Si, So).
|
||||
|
||||
|
||||
|
||||
|
||||
randseq(K, N, S) :-
|
||||
randseq(K, N, L, []),
|
||||
keysort(L, R),
|
||||
strip_keys(R, S).
|
||||
|
||||
|
||||
randseq(0, _, S, S) :- !.
|
||||
randseq(K, N, [Y-N|Si], So) :-
|
||||
random(X),
|
||||
@@ -199,8 +198,8 @@ randseq(K, N, [Y-N|Si], So) :-
|
||||
randseq(K, N, Si, So) :-
|
||||
M is N-1,
|
||||
randseq(K, M, Si, So).
|
||||
|
||||
|
||||
|
||||
|
||||
strip_keys([], []) :- !.
|
||||
strip_keys([_-K|L], [K|S]) :-
|
||||
strip_keys(L, S).
|
||||
@@ -212,14 +211,10 @@ setrand(rand(X,Y,Z)) :-
|
||||
X > 0,
|
||||
X < 30269,
|
||||
Y > 0,
|
||||
Y < 30307,
|
||||
Y < 30307,
|
||||
Z > 0,
|
||||
Z < 30323,
|
||||
setrand(X,Y,Z).
|
||||
|
||||
getrand(rand(X,Y,Z)) :-
|
||||
getrand(X,Y,Z).
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user