home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / modula2 / library / queuem2 / makeseed.mod < prev    next >
Text File  |  1989-08-02  |  2KB  |  63 lines

  1. (* source: h:\modula\code\random\MakeSeed.MOD   v1.0a       revised: 88.07.01
  2.    author: G.Greene, AGCS D/429 (NS/TS), 312/681-7783       created: 88.07.01
  3.  
  4.    function:
  5.     This file contains the implementation code for a module which mangles the
  6.     system date and time into a sort-of random starting value to use a the
  7.     parameter to SetSeedValue in module UnifRNG.
  8.  
  9.    history:
  10.     88.07.01  1.0a  initial release
  11. *)
  12.  
  13.  
  14. IMPLEMENTATION MODULE MakeSeed;
  15.  
  16.  
  17. FROM  SYSTEM  IMPORT (*TYPE*) Registers;
  18.  
  19. FROM  Lib     IMPORT (*PROC*) Dos;
  20.  
  21.  
  22. (*  Return as the function value a value suitable for use as the parameter to
  23.     procedure SetSeedValue in module UnifRNG.  This value will be different
  24.     every time it is called, so that one can get different random sequences
  25.     from any of the random number generators (since all of them ultimately
  26.     use uniform variates from UnifRNG).
  27.     Implementation note:  since this procedure is likely to be called only
  28.     once in any application, it is not designed for time efficiency.  If the
  29.     compiler has options for speed vs. code size optimization, the code size
  30.     optimization should be chosen.
  31. *)
  32.  
  33. PROCEDURE  MakeSeedValue ( ): LONGCARD;
  34.  
  35.   TYPE
  36.     LongCardMasks =
  37.       RECORD
  38.         CASE  which: BOOLEAN  OF
  39.           TRUE:
  40.             longvalue: LONGCARD;
  41.         |
  42.           FALSE:
  43.             lowvalue,
  44.             highvalue: CARDINAL;
  45.         END;   (* CASE *)
  46.       END;   (* LongInt *)
  47.  
  48.   VAR
  49.     Regs:     Registers;
  50.     LongCard: LongCardMasks;
  51.  
  52.   BEGIN
  53.     Regs .AH := 2CH;
  54.     Dos ( Regs );
  55.  
  56.     LongCard .highvalue := Regs .DX;
  57.     LongCard .lowvalue  := Regs .CX;
  58.  
  59.     RETURN  LongCard .longvalue;
  60.   END  MakeSeedValue;
  61.  
  62. END MakeSeed.
  63.