xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_Random()

Generates a random number between two boundaries.

Syntax

HB_Random( [<nMaxLimit>] ) --> nRandomNumber
or
HB_Random( <nMinLimit>, <nMaxLimit> ) --> nRandomNumber

Arguments

<nMaxLimit>
<nMaxLimit> is a numeric value specifying the upper boundary of the random number generator. It defaults to 1.
<nMinLimit>
<nMinLimit> is a numeric value specifying the lower boundary of the random number generator. It defaults to 0. Note that the first parameter is only interpreted as lower boundary when two parameters are passed.

Return

The function returns a random numeric value with two decimal digits, limited by the two boundaries.

Description

This function generates a random number between two boundaries. The boundary values are excluded from the range. When only one boundary is passed to the function, it is considered the maximum boundary. The minimum boundary, in that case, is zero. When no boundaries are passed, the function returns a number between 0.00 and 1.00.

Note  Use function HB_RandomInt() to generate random integer values.

Info

See also:HB_RandomInt(), HB_RandomSeed()
Category: Numeric functions , Random generator , xHarbour extensions
Source:rtl\hbrandom.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the three possibilities of generating
// random numbers with HB_Random().

   PROCEDURE Main
      // Random number between 0.01 and 0.99
      ? HB_Random()

      // Random number between 0.01 and 9.99
      ? HB_Random(10)

      // Random number between 8.01 and 9.99
      ? HB_Random(8,10)
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe