[comp.lang.pascal] HP Pascal: How to implement random number generator?

robert@wiliki.eng.hawaii.edu (Robert Morelos-Zaragoza) (01/11/91)

I am using HP Pascal and wanted to use a random generator function,
just as in Turbo Pascal. Much to my surprise, the manual does not
contain any such function! Please e-mail any sugestion.

Thank you,

Robert Morelos

bigelow@hpfcso.HP.COM (Jim Bigelow) (01/12/91)

> I am using HP Pascal and wanted to use a random generator function,
> just as in Turbo Pascal. Much to my surprise, the manual does not
> contain any such function! Please e-mail any sugestion.

Try calling the Unix (HP-UX) function rand from your pascal program as in the 
following example.

Best Regards,

Jim Bigelow
Pascal
Colorado Lang. Lab.
HP
Ft. Collins, CO

-----

{
    Title: 	random.p -- generate random numbers by calling libc 
			    routine rand(3C)
    Last Mod: 	Fri Jan 11 11:35:00 1991
    Author: 	Jim Bigelow
		<jimb@hpjb>
}
program random (input,output);
    var
    	i : integer;
	seed : integer;
	
    	function rand : integer; external;
    	procedure srand(seed:integer); external;

    begin
    	write('Enter seed: ');
	read(seed);
	srand(seed);
	for i := 1 to 10 do
	    writeln(i,rand);
    end. {random}