home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / vms / 19486 < prev    next >
Encoding:
Text File  |  1992-12-18  |  2.2 KB  |  66 lines

  1. Newsgroups: comp.os.vms
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!nic.umass.edu!umassd.edu!ulowell!woods.ulowell.edu!welchb
  3. From: welchb@woods.ulowell.edu
  4. Subject: Re: Looking for a PASCAL random number function
  5. Message-ID: <1992Dec17.155314.1@woods.ulowell.edu>
  6. Lines: 54
  7. Sender: usenet@ulowell.ulowell.edu (News manager - ulowell)
  8. Organization: University of Lowell
  9. References: <16DEC199215373672@vax2.concordia.ca>
  10. Date: Thu, 17 Dec 1992 20:53:14 GMT
  11.  
  12. program random (output);
  13. var i,seed: integer;
  14.     answer: real;
  15. function mth$random (var seed:integer): real;extern;
  16.  
  17. begin
  18. seed := clock;
  19. for i := 1 to 10 do
  20.         begin
  21.         answer := mth$random(seed); 
  22.         writeln (i:3, '   ', seed:10, ' =seed (decimal),',answer:5, ' =answer');
  23.         end;
  24. end.
  25.  
  26. Note that in this example, the first seed comes from the clock (in order to make
  27. the seed to be almost a random number itself); if you want the program to 
  28. generate the same repeatable sequence of 10 supposedly random numers each time
  29. the program is run, then fill the first seed with some number yourself (I would 
  30. avoid using zero).   The seed gets updated automatically with each call to
  31. mth$random.   answer is in range from 0.0 (inclusive) to 1.0 (exclusive). 
  32. REFERENCES ON RANDOM NUMBERS:
  33. Volume 8C, page RTL-433.
  34. BYTE magazine, 1987 March.
  35. Fortran Users Guide, page B-12.
  36. Programming in Vax Fortran, page D-42.
  37. Basic Program Workbook (Using VMS), page 11-4.
  38. ==============================================================================
  39. ==============================================================================
  40. --- BASIC:  
  41. 20 answer = rnd
  42.         or
  43. 10 randomize
  44. 20 answer = rnd
  45.  
  46.    The first method generates the same "random" number each time the program
  47. is run.  Answer is between 0.0 and 1.0 (inclusive).
  48.  
  49. --- FORTRAN:
  50.     integer*4 seed
  51.     seed = large odd integer value
  52.     answer = ran (seed)
  53. c    a run from a given seed is repeatable at another time with same results.
  54.  
  55. --- PASCAL:
  56. See RANDOM.PAS  ! above the "=============" line
  57.  
  58. Or, here is a write-your-own
  59. FUNCTION RANDOM (VAR seed:INTEGER) : REAL;
  60. BEGIN
  61.    random := seed / 65535;
  62.    seed := (25173 * seed + 13849) mod 65536;
  63. END;
  64. -- 
  65. Brendan Welch, UMass/Lowell, W1LPG,  welchb@woods.ulowell.edu
  66.