michaelslamet Posted April 16, 2011 Share Posted April 16, 2011 Hi all, I need to add randomize character(s) into a string. Let say I have this string: $str = "This is my string, i love it so much" I need to make this string unique every time I run my application. for example, add a "!" chracter to the end of the string: "This is my string, i love it so much!" or/and add 2 "!!" character to the end of the string: "This is my string, i love it so much!!" or/and add white space(s) into the string: "This is my string, i love it so much!!" |_> this is 2 spaces or/and substitute a word(s): "This is my word, i like it so much!!" I need to make it as many as variations I can. Any idea how to make it randomize? Maybe based on random number or time or the other? Thanks a lot Link to comment Share on other sites More sharing options...
Skitty Posted April 16, 2011 Share Posted April 16, 2011 (edited) Hi all, I need to add randomize character(s) into a string. Let say I have this string: $str = "This is my string, i love it so much" I need to make this string unique every time I run my application. for example, add a "!" chracter to the end of the string: "This is my string, i love it so much!" or/and add 2 "!!" character to the end of the string: "This is my string, i love it so much!!" or/and add white space(s) into the string: "This is my string, i love it so much!!" |_> this is 2 spaces or/and substitute a word(s): "This is my word, i like it so much!!" I need to make it as many as variations I can. Any idea how to make it randomize? Maybe based on random number or time or the other? Thanks a lot Off the top of my head, what I'd probably do is create an array with the random character combinations you prefer, and have the random characters selected into another variable using... never mind heres what I would do Global $J[11], $m = "", $I $J[1] = "!" $J[2] = "~" $J[3] = "*" $J[4] = "%" $J[5] = "&" $J[6] = "+" $J[7] = "(" $J[8] = "@" $J[9] = "#" $J[10] = "^" For $I = 1 To Random(1,9,1) $M &= $J[Random(1,9,1)] Next ConsoleWrite($M&@CRLF) maybe something like this ? Edited April 16, 2011 by System238 Link to comment Share on other sites More sharing options...
michaelslamet Posted April 16, 2011 Author Share Posted April 16, 2011 Hi System238, Thanks a lot for your reply. That is not really I want, but thanks for the idea I think i need to assign a substitute words $str = "This is my string, i love it so much" $subs_my[0] = "our" $subs_my[1] = "his" $subs_my[2] = "her" $subs_my[3] = "their" $subs_my[4] = "my" $subs_love[0] = "like" $subs_love[1] = "love" $subs_so[0] = "very" $subs_so[1] = "so" and add a "!" or "!!" or "!!!" character in the end of string. This will make many variation of the string. btw, how to add another white space between words? How is the logic? for example: "this is" become "this is" thanks! Link to comment Share on other sites More sharing options...
Damein Posted April 16, 2011 Share Posted April 16, 2011 (edited) Here is how I would do it:#include <Array.au3> Global $Letter[26] $RandomNumber = Random(1,5,1) For $i = 1 To $RandomNumber Step +1 $Letter[$i] = Chr(Random(Asc("A"), Asc("Z"), 1)) Next $String = _ArrayToString($Letter, "") ConsoleWrite($String)Now you will get a random number between 1-5.Depending on that, you will get x amount of random letters and then that will be outputted to a string.For example:$RandomNumber = 3$Letter[1] = A$Letter[2] = Y$Letter[3] = ROutput is: AYRYou can then put those into another string.Hope this helps Let me know if you have any questions.*** EDIT ***I read your post after making this one ^^;I wrote another quick script that does what you want, but I ran into a bug. If the word to replace is the "is" it also replaces the "is" in "This" so you could get a weird outcome. Maybe someone can fix this? I dunno that much about RegExpReplace ^^; just was trying to help.But, here is my attempt!global $NewString $File = "Dict.txt" $RandomLine = Random(1,8113,1) $Word = FileReadLine($File, $RandomLine) $String = "This is my string, I love it so much" $StringSplit = StringSplit($String, " ") $RandomWord = Random(1,$StringSplit[0],1) $StringRegExp = StringRegExpReplace($String,$StringSplit[$RandomWord],$Word) ConsoleWrite($StringRegExp) ExitAnd the text document it refers to is a list of 8113 words which can be downloaded from here: Download Link Edited April 16, 2011 by Damein Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
UEZ Posted April 16, 2011 Share Posted April 16, 2011 Maybe something like this? $str = "This is my string, i love it so much" $out = "" For $i = 1 To 10 $str &= "!" $out &= $str & @CRLF Next ConsoleWrite($out & @CRLF) Br, UEZ benCao 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
michaelslamet Posted April 20, 2011 Author Share Posted April 20, 2011 Thanks a lot, folks! Now I have an idea how to accomplish this 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