udfStrRandom (iMaxLen)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrRandom_1 (iMaxLen)
; sChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,?!1234567890;:'`"
sChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
iCharsLen = StrLen(sChars) - 1
iRandom = 1 + Random(iMaxLen - 1)
sRandom = ""
For i=1 To iRandom
   sRandom = StrCat(sRandom,StrSub(sChars,1+Random(iCharsLen),1))
Next
Return (sRandom)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrRandom_2 (iMaxLen)
iRandom = 1 + Random(iMaxLen - 1)
sRandom = ""
For i=1 To iRandom
   sRandom = StrCat(sRandom,Num2Char(65 + Random(25)))
Next
Return (sRandom)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------



; --- test ---

msgtitle = "Demo  udfStrRandom (iLen)"
BoxOpen(msgtitle,"")

iCountMax = 100  ; how many strings?
iMaxLen   = 80   ; which length?

For t=1 To 2
   sRandomList = ""
   Exclusive(@ON)
   start=GetTickCount()
   For i=1 To iCountMax
      sRandom = udfStrRandom_%t% (iMaxLen)
      sRandomList = ItemInsert(sRandom,-1,sRandomList,@TAB)
      If !(i mod (iCountMax/10)) Then BoxText(StrCat("Test %t%: creating items ...",@LF,iCountMax,"/",i,@LF,sRandom))
   Next
   stop=GetTickCount()
   Exclusive(@OFF)
   Ticks%t% = stop-start

   IntControl(63,100,200,900,800)
   AskItemlist(msgtitle,sRandomList,@TAB,@UNSORTED,@SINGLE)
Next

MaxTicks = Max(Ticks1,Ticks2)
Pct1 = 100*Ticks1/MaxTicks
Pct2 = 100*Ticks2/MaxTicks

msgtext = StrCat("Performancetest",@LF)
msgtext = StrCat(msgtext,"ticks1=",ticks1,@TAB,Pct1,"%%",@LF)
msgtext = StrCat(msgtext,"ticks2=",ticks2,@TAB,Pct2,"%%",@LF)
Message (msgtitle,msgtext)
ClipPut(msgtext)

:CANCEL
BoxShut()
Exit
;------------------------------------------------------------------------------------------------------------------------------------------
;   WinBatch Studio Run
;   Performancetest
;   ticks1=9315 100%
;   ticks2=6625 71%  <== The Winner.
;------------------------------------------------------------------------------------------------------------------------------------------
;*EOF*