swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
  Related Topics   Other Library Functions  
function  

random.uniform

 
 

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

Returns: A pseudo-random number


Declaration

define external integer function random.uniform
   from value integer low    optional
   to   value integer high   optional

Argument definitions

low
The smallest number that can be generated
high
The largest number that can be generated


Purpose

This function returns a pseudo-random number in the given range. If the lower bound is not given, 0 is used. If the higher bound is not given, then random.max-random is used.

This program outputs 10 random numbers between 0 and random.max-random (32767), inclusive:

  import "omutil.xmd" prefixed by util.
  import "omrandom.xmd" prefixed by random.
  
  process
     random.set-seed to util.millisecond-time
     repeat to 10
        output "d" % random.uniform || "%n"
     again

This program outputs 5 random numbers between 1 and 6, inclusive:

  import "omutil.xmd" prefixed by util.
  import "omrandom.xmd" prefixed by random.
  
  process
     random.set-seed to util.millisecond-time
     repeat to 5
        output "d" % random.uniform from 1 to 6 || " "
     again
     output "%n"

In the examples above, random.set-seed uses the millisecond timer value to "prime" the random number generator. This ensures a different sequence of pseudo-random numbers each time the program is run.

The distribution of returned values over the range is uniform. (Each value has the same chance of occurring.)

The difference between the upper and lower bounds should not exceed random.max-random (32767). If it does, not all discrete values in the range may be returned.

    Related Topics
 
Other Library Functions
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:38:10 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.