[Oberon] Is there anybody out there ...

Jörg joerg.straube at iaeth.ch
Mon Jan 10 15:59:10 CET 2022


Just for your info:
My jr.RandomNumbers.Mod in Oberon-07 looks like this:
I implemented the slightly better Park-Miller instead of the one you find in Oberon books.
Jörg

. . . . . . . 
MODULE RandomNumbers; (* jr/3dec19 *)
IMPORT SYSTEM, Math;
CONST
	timer = -64;

(* Park-Miller 1993 *)
	a = 48271; m = 7FFFFFFFH; q = m DIV a; r = m MOD a;

VAR z*: INTEGER;

PROCEDURE Time(): LONGINT;
	VAR msec: LONGINT; BEGIN SYSTEM.GET(timer, msec); RETURN msec END Time;


PROCEDURE Uniform*(): REAL;				(* returns a random nbr 0 < x < 1 *)
	(*   z = a * z MOD m   by Schrage's method *)
	BEGIN
		z := a*(z MOD q) - r*(z DIV q);
		IF z < 0 THEN INC(z, m) END
	RETURN FLT(z) / FLT(m)
	END Uniform;


PROCEDURE RND*(max: INTEGER): INTEGER;		(* returns an integer in the range 0..max-1 *)
	RETURN FLOOR(Uniform() * FLT(max))
	END RND;


PROCEDURE Exp*(mu: REAL): REAL;			(* returns an exponentially distributed random number *)
	RETURN -Math.ln(Uniform())/mu END Exp;


PROCEDURE InitSeed*(seed: INTEGER);
	BEGIN
		IF seed = 0 THEN z := 1 ELSE z := seed END;
	END InitSeed;

BEGIN
	InitSeed(Time())
END RandomNumbers.

ORP.Compile jr.RandomNumbers.Mod/s ~
System.Free RandomNumbers ~
. . . . . . .

Am 07.01.22, 10:40 schrieb "Oberon im Auftrag von Ka-Pe Er" <oberon-bounces at lists.inf.ethz.ch im Auftrag von k_p_r at gmx.de>:

    In my search for as original as possible OBERON(-2) source texts for
    testing the Rochus Keller Oberon+ system, I have now (after the modules
    RandomNumbers, ListRN and IFS) also successfully compiled the two models
    from PiO (Programming in Oberon, Reiser & Wirth) using ETH Plugin Oberon
    for Windows.
    In doing so, I found some very irritating "errors", which can be found
    in the original English version as well as in the later German edition:

    1. The module RandomNumbers has an additional, exported function Exp in
    both models, which is not included in the source code at the front of
    the book, but was then discovered by me in the ETH Oberon (Plugin Oberon
    for Windows) source code-wise.
    2. Even Sequences, which is unfortunately only available as a definition
    module in an exercise, apparently has an additional procedure Open in
    Setup in the second Model, although this could perhaps be covered by Init.

    Is there anybody out there ...
    who knows some official (?) "sample solutions" of this / all PiO-tasks
    as source code from your student days ?

    Thanks
    Klaus-Peter Reimers
    (Germany / Kiel)
    --
    Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
    https://lists.inf.ethz.ch/mailman/listinfo/oberon




More information about the Oberon mailing list