(* This is a port of the System3 or V4 RNG. You should use Random.Mod instead. *) MODULE RandomNumbers; IMPORT Texts, Oberon, SYSTEM; VAR z, td: INTEGER; W: Texts.Writer; PROCEDURE Uniform*(): REAL; CONST a = 16807; m = 2147483647; q = m DIV a; r = m MOD a; VAR g: INTEGER; BEGIN g := a * (z MOD q) - r * (z DIV q); Texts.WriteInt(W, g, 12); Texts.WriteLn(W); IF g > 0 THEN z := g ELSE z := g + m END; Texts.WriteInt(W, z, 12); Texts.WriteLn(W); RETURN FLT(z) * 1.0 / FLT(m) END Uniform; PROCEDURE InitSeed*(seed: INTEGER); BEGIN z := seed END InitSeed; PROCEDURE Test*; BEGIN Texts.WriteReal(W, Uniform(), 12); Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf) END Test; (* The Pepino RTC never ticks. And a time of 0 is an edge case that always gives the same "random" number. Everything works fine if you manually set the time with System.Date first. TODO: is there any other entropy hardware? A: doesn't look like it from the schematics *) BEGIN Texts.OpenWriter(W); td := Oberon.Clock(); Texts.WriteInt(W, td, 12); Texts.WriteLn(W); z := SYSTEM.VAL(INTEGER, td); Texts.WriteInt(W, z, 12); Texts.WriteLn(W); END RandomNumbers.