xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_RandomInt()

Generates a random integer number between two boundaries.

Syntax

HB_RandomInt( [<nMaxLimit>] ) --> nRandomInteger
or
HB_RandomInt( <nMinLimit>, <nMaxLimit> ) --> nRandomInteger

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 integer value, limited by the two boundaries.

Description

This function generates a random number between two boundaries. The boundary values are included in 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 0 or 1.

Note  Use function HB_Random() to generate random numeric values with two decimals.

Info

See also:HB_Random(), 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_RandomInt().

   PROCEDURE Main
      // Random creation of 0 and 1
      ? HB_RandomInt()

      // Random number between 0 and 10
      ? HB_RandomInt(10)

      // Random number between 8 and 10
      ? HB_RandomInt(8,10)
   RETURN

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