The Mercury random module

Lourens van der Meij lourens at cs.vu.nl
Thu Jul 3 17:25:08 AEST 1997


/*
Dear list members,

I tried to use the random module functionality in one of my first 
Mercury test programs. The random module does not seem to function as I 
would expect.

In the following program I use random__test/4 that is part of the
Mercury random module. Is it correct that random__random should generate
negative integer values? I use mercury0.6, the binary distribution for 
Solaris.

Kind regards,

Lourens van der Meij

lourens at cs,vu.nl

random__test(10, 10, L, M) produced as result:
random list:
398601
1266332
-137868
-1374022
1173335
-1562370
1496442
-560858
-945987
530895
 
max:1771874

*/
:- module rndprob.
:- interface.
:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

:- import_module random.

main --> 
	{ random__test(10, 10, L, M) },
	io__write_string("\nrandom list:\n"),
	rndtest___write_ints(L),
	io__write_string("\nmax:"),
	io__write_int(M),
	io__write_string("\n"),
	io__write_string("End of program\n").


:- pred rndtest___write_ints(list(int)::in, io__state::di, io__state::uo) is det.

rndtest___write_ints([]) --> {true}.

rndtest___write_ints([F|R]) -->
	io__write_int(F),
	( { R = [] }
	->	io__write_string("\n")
	;	io__write_string("\n")
	),
	rndtest___write_ints(R).




More information about the users mailing list