home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 09 / ml.lst < prev    next >
File List  |  1991-08-21  |  1KB  |  43 lines

  1. _ML AND COLORED PETRI NETS FOR MODELING AND SIMULATION_
  2. by Peter D. Varhol
  3.  
  4. [LISTING ONE]
  5.  
  6.  
  7. (* A list generator for the processes *)
  8.  
  9. fun listGenerator start next 0 = nil
  10.     | listGenerator start next n = start :: 
  11.     listGenerator (next start) next (n - 1)
  12.  
  13.  
  14. (* Random number generator.  Uses the congruence method. *)
  15.  
  16. fun random seed = let val x = (power 7.0 9.0) * seed mod (power 10.0 10.0)
  17.             in x - real(floor x)
  18.             end;
  19. val seed = random seed;
  20.  
  21.  
  22. (* Seed value for the random number generator.  This number should *)
  23. (* be changed for every simulation run to produce a different random *)
  24. (* number list. *)
  25.  
  26. val seed = .5
  27.  
  28.  
  29. (* Functions to produce the list of random numbers.  Calls the list *)
  30. (* and the random number function, and places the results in randomList. *)
  31.  
  32. fun proclist n seed = listGenerator seed random n;
  33. fun ranint a b c = floor(x * real(b - a + 1)) + a;
  34. fun randomList = x yx z seed = map(randint x y) (proclist z seed);
  35.  
  36.  
  37. (* Part of a sample processor in the multiprocessor system.  CountDown *)
  38. (* is a recursive function that serves as the relative time clock. *)
  39.  
  40. fun processorOne randomList = countDown (map(randomList))
  41.                 statistics randomList;
  42.  
  43.