Quote from iretz on January 29, 2022, 6:43 amRandom "[NewLength]" "[RandNum]"
... if Random number 10
StrReplace "[RandNum]" "0" "1" "[RandNum]" ""
... then the random number here will be 11
Random "[NewLength]" "[RandNum]"
... if Random number 10
StrReplace "[RandNum]" "0" "1" "[RandNum]" ""
... then the random number here will be 11

Quote from Vadim on January 29, 2022, 12:49 pm
@pauljonestindall
Thanks @iretz ! So it's still better to use a logical condition to bypass zero.
Thanks @iretz ! So it's still better to use a logical condition to bypass zero.
Quote from Gaev on January 29, 2022, 6:35 pmAt the risk of messing up (again), hope you find this VisualNEOWin code useful.
It incorporates a trick I learned a long time ago, to work around the fact that Random works with a base of zero, while string positions use a base of 1 ... also avoids having to check for a randomized result of zero.
SetVar "[OriginalText]" "qwertyqwerty" StrLen "[OriginalText]" "[OriginalTextLength]" ... copy to working text variable SetVar "[thisText]" "[OriginalText]" StrLen "[thisText]" "[thisTextLength]" SetVar "[RandomizedText]" "" Loop "1" "[OriginalTextLength]" "[thisLoop]" ... get current string length StrLen "[thisText]" "[thisTextLength]" ... get random number between zero and 'text length minus 1' Random "[thisTextLength]-1" "[thisRandomNumber]" ... recalibrate for base 0 Math "[thisRandomNumber]+1" "0" "[thisTextPosition]" ... extract character SubStr "[thisText]" "[thisTextPosition]" "1" "[thisExtractedCharacter]" ... append to [RandomizedText] SetVar "[RandomizedText]" "[RandomizedText][thisExtractedCharacter]" ... remove from [thisText] StrDel "[thisText]" "[thisTextPosition]" "1" "[thisText]" ...AlertBox "Trace" "[thisLoop]|[thisTextLength]|[thisTextPosition]|[thisExtractedCharacter]|[RandomizedText]" EndLoop AlertBox "Randomized Text" "[RandomizedText]"It works for me; let me know if your experience is different.
At the risk of messing up (again), hope you find this VisualNEOWin code useful.
It incorporates a trick I learned a long time ago, to work around the fact that Random works with a base of zero, while string positions use a base of 1 ... also avoids having to check for a randomized result of zero.
SetVar "[OriginalText]" "qwertyqwerty" StrLen "[OriginalText]" "[OriginalTextLength]" ... copy to working text variable SetVar "[thisText]" "[OriginalText]" StrLen "[thisText]" "[thisTextLength]" SetVar "[RandomizedText]" "" Loop "1" "[OriginalTextLength]" "[thisLoop]" ... get current string length StrLen "[thisText]" "[thisTextLength]" ... get random number between zero and 'text length minus 1' Random "[thisTextLength]-1" "[thisRandomNumber]" ... recalibrate for base 0 Math "[thisRandomNumber]+1" "0" "[thisTextPosition]" ... extract character SubStr "[thisText]" "[thisTextPosition]" "1" "[thisExtractedCharacter]" ... append to [RandomizedText] SetVar "[RandomizedText]" "[RandomizedText][thisExtractedCharacter]" ... remove from [thisText] StrDel "[thisText]" "[thisTextPosition]" "1" "[thisText]" ...AlertBox "Trace" "[thisLoop]|[thisTextLength]|[thisTextPosition]|[thisExtractedCharacter]|[RandomizedText]" EndLoop AlertBox "Randomized Text" "[RandomizedText]"
It works for me; let me know if your experience is different.

Quote from Vadim on January 29, 2022, 8:31 pm@gaev
It works perfectly! Great trick with the zero bypass!!! That hadn't occurred to me! Thanks for sharing!!! Very interesting!!!
It works perfectly! Great trick with the zero bypass!!! That hadn't occurred to me! Thanks for sharing!!! Very interesting!!!
Quote from Gaev on January 29, 2022, 11:39 pm@vadim
For those developers who need to do the base conversion often, I suggest making up a Function that can then be Call'ed e.g.
Call "RandomBase1" "[MaxNumber]" "[RandomResult]"
For those developers who need to do the base conversion often, I suggest making up a Function that can then be Call'ed e.g.
Call "RandomBase1" "[MaxNumber]" "[RandomResult]"
Quote from PaulJonestindall on January 31, 2022, 1:28 pm@vadim
Yes, I see. If the very first random number generated is 10, the zero is changed to 1, making the number 11. the is no character in the eleventh position to read, no character to delete and therefore the length doesn't change through the next loop leaving one unread character in the original text entry.
You have to use if...then rather than StrReplace.
Yes, I see. If the very first random number generated is 10, the zero is changed to 1, making the number 11. the is no character in the eleventh position to read, no character to delete and therefore the length doesn't change through the next loop leaving one unread character in the original text entry.
You have to use if...then rather than StrReplace.