xHarbour Reference Documentation > Function Reference |
Sets the seed for generating random numbers.
HB_RandomSeed( [<nSeed>] ) --> NIL
The function returns always NIL.
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.
See also: | HB_Random(), HB_RandomInt() |
Category: | Numeric functions , Random generator , xHarbour extensions |
Source: | rtl\hbrandom.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com