Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Suggestions for random candidate key generation methodol
Message
From
11/05/2004 12:02:02
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00902286
Message ID:
00902858
Views:
29
Thanks Sergey!

Tracy

>Hi Tracy,
>
>Here's function I'm using to get next key.
* Purpose   Creates next string key from the passed one
>*			using specified set of characters
>*
>*  Param's
>*            1 - Current Key
>*            2 - Defines the list of allowed characters
>*            		BASENN - See DO CASE in the body of the program
>*					CUSTOM - the list of character as parameter 3
>*            3 - List of characters
>*   Return  New Key
>*
>*    Note : Routine ignores (doesn't change) the positions
>*				with the characters not in the specified list
>
>PARAMETER tcOldVal, tcOpt, tcCharList
>
>LOCAL lcNewVal, i, lcDigits, lcLetters, lnStrLen, lcOldChar, lcNewChar, lcCharList, lnPos
>
>lcOpt = IIF(EMPTY(tcOpt), "BASE10", UPPER(tcOpt))
>* Fill out the string 'lcCharList' with all characters
>lcDigits = "0123456789"
>lcLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
>
>DO CASE
>CASE "CUSTOM" $ lcOpt
>	lcCharList = tcCharList
>CASE "BASE10" $ lcOpt
>	* Just Digits
>	lcCharList = lcDigits
>CASE "BASE16L" $ lcOpt
>	* Hex-dec lower
>	lcCharList = lcDigits + "abcdef"
>CASE "BASE16" $ lcOpt
>	* Hex-dec upper
>	lcCharList = lcDigits + "ABCDEF"
>CASE "BASE26L" $ lcOpt
>	* Lower case letters
>	lcCharList = LOWER(lcLetters)
>CASE "BASE26" $ lcOpt
>	* Upper case letters
>	lcCharList = lcLetters
>CASE "BASE36L" $ lcOpt
>	* Digits + Lower case letters
>	lcCharList = lcDigits + LOWER(lcLetters)
>CASE "BASE36" $ lcOpt
>	* Digits + Upper case letters
>	lcCharList = lcDigits + lcLetters
>CASE "BASE52" $ lcOpt
>	* All letters
>	lcCharList = lcLetters + LOWER(lcLetters)
>CASE "BASE62" $ lcOpt
>	* Digits + All letters
>	lcCharList = lcDigits + lcLetters + LOWER(lcLetters)
>OTHERWISE
>	* The same as BASE10
>	lcCharList = lcDigits
>ENDCASE
>
>lnStrLen = LEN(lcCharList)
>
>lcNewVal = tcOldVal
>
>* Scan Val string from the right to the left
>
>FOR i = LEN(lcNewVal) TO 1 STEP -1
>
>	lcOldChar = SUBSTR(tcOldVal, i, 1)
>
>	IF NOT (lcOldChar $ lcCharList)
>		* Keep it
>		LOOP
>	ENDIF
>
>	* Get the next character for this position
>	*lcNewChar = GetNextChar( lcOldChar, lcCharList )
>	lnPos = AT(lcOldChar, lcCharList)
>
>	IF lnPos = lnStrLen
>		* It's last character
>		lcNewChar = LEFT(lcCharList,1)
>	ELSE
>		* Get the next character
>		lcNewChar = SUBSTR(lcCharList, lnPos+1,1)
>	ENDIF
>
>	lcNewVal = STUFF(lcNewVal, i, 1, lcNewChar)
>	IF lcNewChar <> LEFT(lcCharList,1)
>		* We got next one
>		EXIT
>	ENDIF
>
>ENDFOR
>
>RETURN lcNewVal
>
>
>>
>>This is in VB, but I found it useful:
>>
>>http://accessadvisor.net/doc/03419
>>
>>and for a little humor:
>>
>>http://www.rgrossman.com/dl/proc-074.pdf
>>
>>:o)
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform