Sign in to follow this  
Followers 0
michaelslamet

Add randomize character(s) into a string

6 posts in this topic

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 :unsure:

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 :unsure:

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 by System238

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Hi System238,

Thanks a lot for your reply.

That is not really I want, but thanks for the idea :unsure:

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! :>

Share this post


Link to post
Share on other sites

#4 ·  Posted (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] = R

Output is: AYR

You can then put those into another string.

Hope this helps :unsure:

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)

Exit

And the text document it refers to is a list of 8113 words which can be downloaded from here:

Download Link

Edited by Damein

MCR.jpg?t=1286371579

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

Share this post


Link to post
Share on other sites

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


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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks a lot, folks! Now I have an idea how to accomplish this :unsure:

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0