hb_R - Petewg/harbour-core GitHub Wiki
-
hb_Rand32() ➜ nRandomInt
returns a randomly grabbed integer between0
and0xFFFFFFFF
inclusive. - (0xFFFFFFFF = 4.294.967.295) -
hb_randInt(
[<x> [, <y>]]
) ➜ nRandomInt
returns an integer random number which, if no parameter argument passed, is0
or1
, or between0
and<x>
or between<x>
and<y>
, if relevant params passed. -
hb_randNum(
[<x> [, <y>]]
) ➜ nRandom
returns a floating point random number which is between0
and1
, when no parameter argument passed, or between0
and<x>
or between<x>
and<y>
when one or two arguments used respectively.NOTE: As we can see looking into the sources, the above two functions use ARC4 based PRNG (Pseudo Random Number Generator) to generate randomness, while the two below use a Harbour own algorithm (time & stack based). Now, which one of the two methods is more effective (i.e. which one achieves the better randomness) remains to be proved during real-life usage. Either way, the computational methods in generation of "true" random numbers is a quite long-lasting (and debatable) story.
-
hb_Random(
[<x> [, <y>]]
) ➜ nRandomReal
returns a (floating point) number<n>
so that:0 <= n < 1
(if no params passed), or0 <= n < x
(if only<x>
passed), orx <= n < y
(if<x>, <y>
passed). Note: value of<y>
(if any), is NOT included in values returned. -
hb_RandomInt(
[<x> [, <y>]]
) ➜ nRandomInt
returns an integer number<n>
so that:1 <= n <= x
(when onlyx
passed), orx <= n <= y
(whenx
andy
passed), or0s
and1s
almost evenly distributed (when no params passed). Note: values ofx,y
(if any), are INCLUDED in values returned. -
hb_RandomIntMax() ➜ 2147483645
-
hb_RandomSeed(
<nSeed>
) ➜ NIL
seeds (i.e. initializes) the random number generator used byhb_Rand*
family functions. It may be invoked once, before calling a 'randomizer' function. If the parameternSeed
is0
, then first call to hb_Random() or hb_RandomInt() activates initialization which generates new seed using current time in milliseconds and HVM stack address (for MT modes). If repeatable results needed from hb_Random() and hb_RandomInt() then the seed should be initialized for each thread with some fixed value i.e. hb_RandomSeed( 123456789 ) -
hb_RandStr(
<nChars>
) ➜ cRandChars
returns a string of<nChars>
random characters.
-
hb_RAScan(
<aArray>, <uValue> [, <nStart>, <nCount>, <lExact>]
) ➜ nPosition
Scans (right to left) for<uValue>
into<aArray>
and returns<nPosition>
of found or<zero>
if nothing found. It's same tohb_AScan(...)
but it starts scanning reversely, from right to left (or bottom to top.) -
hb_RAt(
<cSearchFor>, <cIntoString>, [<nStart>], [<nEnd>]
) ➜ nPosition
It finds the last (rightmost) match of<cSearchFor>
into<cIntoString>
in the range<nStart>
-<nEnd>
. IOW, the search is performed from the right to left. -
hb_rddInfo(
<nConstandIndex>, [<xNewSetting>], [<xcRDDName>], [<nConnection>]
) ➜ xCurrentSetting
retrieves and optionally sets configuration settings for RDD used.
For a complete list of settings refer todbinfo.ch
header file. Not all settings are supported by all RDDs.
Returns the current setting, i.e. the value which is / was current, before the new setting (if any) applied. -
hb_releaseCPU() ➜ NIL
releases a CPU time slice, that is, causes current thread (or application) to relinquish the remainder of its time slice, becoming un-runnable (stop running) for about 20 milliseconds (32 on OS/2). -
hb_Run(
<cCommand>
) ➜ nErrorLevel
returns the exit-code (or OS errorlevel) that results by executing (running) of<cCommand>
.
see also: hb_ProcessRun()