xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_RandomSeed()

Sets the seed for generating random numbers.

Syntax

HB_RandomSeed( [<nSeed>] ) --> NIL

Arguments

<nSeed>
A numeric value used as seed for generating the random numbers returned by HB_Random() and HB_RandomInt().

Return

The function returns always NIL.

Description

This function sets the seed value for generating random numbers with HB_Random() and HB_RandomInt(). When a seed value is specified for the random number generator, it produces the same series of random numbers with each program invocation. This is useful for debugging purposes.

Calling the function without an argument resets the seed so that HB_Random() and HB_RandomInt() generate different series of random numbers each time a program is executed.

Info

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

Example

// The example generates two stings holding random upper case characters
// from A to Z. The first string is the same, each time the example is
// executed, while the second differs between program invocations.

   PROCEDURE Main
      LOCAL i, cStr1 := Space(10), cStr2 := Space(10)

      HB_RandomSeed(7)

      FOR i:=1 TO Len( cStr1 )
         cStr1[i] := HB_RandomInt(65,90)
      NEXT

      ? HB_RandomSeed()

      FOR i:=1 TO Len( cStr2 )
         cStr2[i] := HB_RandomInt(65,90)
      NEXT

      ? cStr1
      ? cStr2
   RETURN

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