Navigation:  Examples >

Generating random strings

Previous pageReturn to chapter overviewNext page

http://news.xbwin.com/ot4xb.examples/3/

 

 

Minimum ot4xb build 1.5.2.79

cGenRndStr() is introduced in ot4xb build 1.5.2.54, but a error caused about 10% of duplicates,

which was fixed in 1.5.2.79

 

I've run the test in my computer ( Intel Core Duo 3Ghz, 2Gb RAM) with the following results:

Elapsed Time: 3 Seconds

1000000 Items 0 Duplicates

 

#include "ot4xb.ch"

#define MAX_LOOP  1000000

// ---------------------------------------------------------------------------

function Main()

local nSeconds := Seconds()

local pHt      := _HDICT_NEW(,MAX_LOOP)

local n

for n := 1 to MAX_LOOP

   _HDICT_SETPROP(pHt,cBin2Hex(cGenRndStr(8,.T.)), 0) 

   // cBin2Hex() is needed here as the hash table is case insensitive

next

? cPrintf(" Elapsed Time: %i Seconds",Seconds() - nSeconds)

? cPrintf(" %i Items  %i Duplicates",MAX_LOOP , MAX_LOOP - _HDICT_COUNT(pHt) )

inkey(0)

return NIL

// ---------------------------------------------------------------------------