home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.vms
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!nic.umass.edu!umassd.edu!ulowell!woods.ulowell.edu!welchb
- From: welchb@woods.ulowell.edu
- Subject: Re: Looking for a PASCAL random number function
- Message-ID: <1992Dec17.155314.1@woods.ulowell.edu>
- Lines: 54
- Sender: usenet@ulowell.ulowell.edu (News manager - ulowell)
- Organization: University of Lowell
- References: <16DEC199215373672@vax2.concordia.ca>
- Date: Thu, 17 Dec 1992 20:53:14 GMT
-
- program random (output);
- var i,seed: integer;
- answer: real;
- function mth$random (var seed:integer): real;extern;
-
- begin
- seed := clock;
- for i := 1 to 10 do
- begin
- answer := mth$random(seed);
- writeln (i:3, ' ', seed:10, ' =seed (decimal),',answer:5, ' =answer');
- end;
- end.
-
- Note that in this example, the first seed comes from the clock (in order to make
- the seed to be almost a random number itself); if you want the program to
- generate the same repeatable sequence of 10 supposedly random numers each time
- the program is run, then fill the first seed with some number yourself (I would
- avoid using zero). The seed gets updated automatically with each call to
- mth$random. answer is in range from 0.0 (inclusive) to 1.0 (exclusive).
- REFERENCES ON RANDOM NUMBERS:
- Volume 8C, page RTL-433.
- BYTE magazine, 1987 March.
- Fortran Users Guide, page B-12.
- Programming in Vax Fortran, page D-42.
- Basic Program Workbook (Using VMS), page 11-4.
- ==============================================================================
- ==============================================================================
- --- BASIC:
- 20 answer = rnd
- or
- 10 randomize
- 20 answer = rnd
-
- The first method generates the same "random" number each time the program
- is run. Answer is between 0.0 and 1.0 (inclusive).
-
- --- FORTRAN:
- integer*4 seed
- seed = large odd integer value
- answer = ran (seed)
- c a run from a given seed is repeatable at another time with same results.
-
- --- PASCAL:
- See RANDOM.PAS ! above the "=============" line
-
- Or, here is a write-your-own
- FUNCTION RANDOM (VAR seed:INTEGER) : REAL;
- BEGIN
- random := seed / 65535;
- seed := (25173 * seed + 13849) mod 65536;
- END;
- --
- Brendan Welch, UMass/Lowell, W1LPG, welchb@woods.ulowell.edu
-