youtuber Posted December 13, 2019 Share Posted December 13, 2019 For example, to add random hyphens like this w-ord wor-d wo-rd d-row dro-w dr-ow o-wrd... I tried a lot but I couldn't solve the logic Local $aWord[1] = ['word'] Local $aRandomAdd = "" For $i = 0 To Ubound($aWord)-1 $aRandomAdd = $aWord[$i] $aRandomAdd &= Random(1,StringRight($aWord[$i], $i) & "-",1) Next ConsoleWrite($aRandomAdd & @CRLF) Link to comment Share on other sites More sharing options...
Gianni Posted December 14, 2019 Share Posted December 14, 2019 ? #include <array.au3> Local $sWord = 'word' Local $iNrWantedRandoms = 5, $iRandom, $sStrLen = StringLen($sWord) SRandom(@MSEC) ConsoleWrite('randomly place an hyphen' & @CRLF) For $i = 0 To $iNrWantedRandoms $iRandom = Random(1, $sStrLen - 1, 1) ConsoleWrite(StringLeft($sWord, $iRandom) & '-' & StringRight($sWord, $sStrLen - $iRandom) & @CRLF) Next ConsoleWrite("randomly place an hyphen and also shuffle word's letters" & @CRLF) Local $aWord = StringToASCIIArray($sWord) For $i = 0 To $iNrWantedRandoms _ArrayShuffle($aWord) $sRandomWord = StringFromASCIIArray($aWord) $iRandom = Random(1, $sStrLen - 1, 1) ConsoleWrite(StringLeft($sRandomWord, $iRandom) & '-' & StringRight($sRandomWord, $sStrLen - $iRandom) & @CRLF) Next youtuber 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
iamtheky Posted December 14, 2019 Share Posted December 14, 2019 (edited) #include<string.au3> $str = "word" $insrt = "-" $sOut = "" for $i = 0 to stringlen($str) * 2 - 1 $sOut &= $i < stringlen($str) ? _StringInsert($str , $insrt , random(1 , stringlen($str))) & @LF : stringreverse(_StringInsert($str , $insrt , random(1 , stringlen($str)))) & @LF next msgbox(0, '' , $sOut) did you want them to be in unique positions. more shuffled than random? or really random? and did you want the reverse strings too? edit: i also assumed you didnt want the potential of a leading or trailing hyphen... edit: also, my bad i see now they are shuffled, not just reversed. Edited December 14, 2019 by iamtheky youtuber 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
jugador Posted December 14, 2019 Share Posted December 14, 2019 (edited) nothing related to @youtuber request(randomness) but still.... #include <Array.au3> #include<string.au3> $a_String = 'word' $a_Array = StringSplit($a_String & '-', "", $STR_NOCOUNT) $a_suffel = _ArrayPermute($a_Array, '') _ArrayDelete($a_suffel, 0) _ArrayDisplay($a_suffel) ;$b_string = _ArrayToString($a_suffel) ;Msgbox(0,"", StringRegExpReplace($b_string , "\|(.*?)" , "" & @CRLF)) & not sure use of StringRegExpReplace is correct. Edited December 14, 2019 by jugador youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted December 14, 2019 Author Share Posted December 14, 2019 (edited) @jugador Thank you,That's exactly what I'm looking for. It works well for me. @iamtheky more shuffled than random? = Yes more complicated and shuffled. @iamtheky @Chimp Thank you. The examples are good for me, but why are sometimes similar words listed? Edited December 14, 2019 by youtuber Link to comment Share on other sites More sharing options...
iamtheky Posted December 14, 2019 Share Posted December 14, 2019 Quote but why are sometimes similar words listed I think because the goal of 'random' was a misnomer. Hyphens could all be in the same position and that position still have been randomly selected each time. It is seeming more that you want: 1) the string shuffled 2) a random hyphen placed within the string (not before or after) 3) repeat steps 1 and 2 ensuring the results are all unique is that accurate? do you want the string shuffled every time around the loop? youtuber 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
jchd Posted December 14, 2019 Share Posted December 14, 2019 For a complete list of all allowed results: Local $s = "autoit" Local $a = _ArrayPermute(StringSplit($s & '-', "", 3)) Local $b = StringSplit(StringTrimRight(StringRegExpReplace(_ArrayToString($a, ',', 1) & ',', "((?<!\w|^)-\w+,|\w+-,)", ""), 1), ',', 3) $b = _ArrayUnique($b, 0, 0, 0, 0) _ArrayDisplay($b) youtuber 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
youtuber Posted December 14, 2019 Author Share Posted December 14, 2019 (edited) @jchd Thanks,this wonderful Edited #include <Array.au3> Local $s = "autoit" $a_Array = StringSplit($s & '-', "", $STR_NOCOUNT) $a = _ArrayPermute($a_Array, '') Local $b = StringSplit(StringTrimRight(StringRegExpReplace(_ArrayToString($a, ',', 1) & ',', "((?<!\w|^)-\w+,|\w+-,)", ""), 1), ',', 3) $b = _ArrayUnique($b, 0, 0, 0, 0) ;~ _ArrayDisplay($b) For $i = 0 To UBound($b) - 1 ConsoleWrite($b[$i] & @CRLF) Next Edited December 14, 2019 by youtuber Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now