random.set-seed

function

Library: Random number utilities (OMRANDOM)
Import : omrandom.xmd

Declaration
export external function 
   set-seed to value integer seed


Purpose

random.set-seed provides a seed to prime the random number generator. Different seed values will produce different sequences of numbers. By using the same seed for each run, the sequence of pseudo-random numbers can be kept the same. If the application is using random numbers to perform some kind of simulation, the simulation can be repeated by supplying the same seed.

Example

The following program will generate a different sequence of numbers each time, because the seed is always different:

  import "omutil.xmd"   prefixed by util.
  import "omrandom.xmd" prefixed by random.
  
  process
     local integer seed initial { util.millisecond-time }
  
     output "The seed is: %d(seed)%n"
     random.set-seed to seed
     repeat for integer i to 100
        output "d" % i || ". " || "d" % random.uniform || "%n"
     again

Example

The following program will generate the same sequence of numbers each time, because the seed is always 12345:

  import "omrandom.xmd" prefixed by random.
  
  process
     local integer seed initial { 12345 }
  
     output "The seed is: %d(seed)%n"
     random.set-seed to seed
     repeat for integer i to 100
        output "d" % i || ". " || "d" % random.uniform || "%n"
     again

Other Library Functions