Pascal for ZX81

Discussion about ZX80 / ZX81 Software
User avatar
Paul
Posts: 1511
Joined: Thu May 27, 2010 8:15 am
Location: Germanys west end

Re: Pascal for ZX81

Post by Paul »

Thanks, good to know.
I would have suggested the same, but I wasn't sure if was updated while using Pascal
In theory, there is no difference between theory and practice. But, in practice, there is.
User avatar
Vorticon
Posts: 69
Joined: Tue Mar 01, 2022 1:14 pm

Re: Pascal for ZX81

Post by Vorticon »

Here's an RND routine which will give you a pseudo-random number sequence. Feed it N, the maximum number in the sequence you want up to 4096 and it will return an integer in N between 0 and N-1. For example, N:=RND(10) will return a random number between 0 and 9 stored in N. Make sure you do not overwrite the contents of the R and C variables in the main program.

Code: Select all

PROGRAM TEST(INPUT,OUTPUT);
VAR
 R,C,N:INTEGER
 
FUNCTION RND(V:INTEGER):INTEGER;
VAR
 I,T: INTEGER;
 
BEGIN
 IF C=4096 THEN
  BEGIN
   R:=MEM(.16436.);
   C:=0
  END
 ELSE
  C:=C+1;
 REPEAT
  R:=(5*R+33) MOD 4096;
  T:=R DIV (4096 DIV V);
 UNTIL T<V;
 RND:=T
END;
 
BEGIN (* MAIN PROGRAM *)
  R:=MEM(.16436.);
  C:=0;
  ...
END.
Post Reply