Page 1 of 2
Randomness
Posted: 09 Mar 2011 17:03
by tiago
Hello.
I'm trying to find if XY could random letters like AHK does, like in:
This Should be RaNdoM > d,e,R,s,h,i,T,M,u,S,N,o,l,o,d,b,a,h
I achieved something using "rand", but problem comes with the "formatlist" limitations, as it wipes out unique letters (A != a) since "passing "r", "c", or "n" implies "s"", which by its turn makes "Aa" into "a" or "A". Can this be implemented in "rand" or "formatlist" please?
By the way, any ideas on how I could make XY insert separators in a list, PRESERVING spaces?
690SR8GQ3 YVI57 (690SR8GQ3<space>YVI57) > 6,9,0,S,R,8,G,Q,3, Y,V,I,5,7 (no separators after or before the whole sentence but one after each group that is not the last on the output)
TIA.
Re: Randomness
Posted: 12 Mar 2011 18:54
by tiago
Regarding separators:
$input = "a.b.cs"; //this could work with "abcs" if gettoken could allow usage of empty separators
#217; //clear clip
$cf = gettoken($input, "count", "."); //here
$base = 0;
WHILE ($base < $cf) {
incr $base, $base, 1;
$final = gettoken($input, $base, "."); //and here
set $out, "$final" . ",";
copytext $out, a;
}
status "<clipboard>";
Re: Randomness
Posted: 12 Mar 2011 19:20
by j_c_hallgren
tiago wrote:Regarding separators:
Code: Select all
$input = "a.b.cs"; //this could work with "abcs" if gettoken could allow usage of empty separators
#217; //clear clip
$cf = gettoken($input, "count", "."); //here
$base = 0;
WHILE ($base < $cf) {
incr $base, $base, 1;
$final = gettoken($input, $base, "."); //and here
set $out, "$final" . ",";
copytext $out, a;
}
status "<clipboard>";
Makes it MUCH easier to read/follow script when you use "code" tags so could you please edit post in other thread to add them as well? Thanks
Re: Randomness
Posted: 19 Mar 2011 14:44
by tiago
Admin, can you help me on this?
A flag, perhaps...
Summarizing:
I'm trying to find if XY could random letters like AHK does, like in:
This Should be RaNdoM > d,e,R,s,h,i,T,M,u,S,N,o,l,o,d,b,a,h
XY to insert separators in a list, PRESERVING spaces.
690SR8GQ3 YVI57 (690SR8GQ3<space>YVI57) > 6,9,0,S,R,8,G,Q,3, Y,V,I,5,7 (no separators after or before the whole sentence but one after each group that is not the last on the output)
Re: Randomness
Posted: 19 Mar 2011 19:29
by admin
Look at rand().
Re: Randomness
Posted: 19 Mar 2011 19:50
by tiago
Yes, I played a lot with rand().
Problem comes when I need to ensure that randomized stuff gets uniqued, and the only way to ensure that is removing duplicates, which by its turn requires that formatlist() "dedupes" and dedupe requires sorting, which assumes that A == a, and in my case "A" must not be the same as "a".
So if I have Aa, it'll end up as "A" or "a".
AAa should result Aa if I want the desired effect to happen.
Aaaaaaaa too.
My rand() studies resulted in a lottery mini app, RPG Multi-Dice Roller and Rainbow Six Mission Names Generator out of a friend's request, among more serious and complicated projects like a message encoder/decoder and a password scrambler.
Re: Randomness
Posted: 20 Mar 2011 07:46
by admin
tiago wrote:Yes, I played a lot with rand().
Problem comes when I need to ensure that randomized stuff gets uniqued, and the only way to ensure that is removing duplicates, which by its turn requires that formatlist() "dedupes" and dedupe requires sorting, which assumes that A == a, and in my case "A" must not be the same as "a".
So if I have Aa, it'll end up as "A" or "a".
AAa should result Aa if I want the desired effect to happen.
Aaaaaaaa too.
My rand() studies resulted in a lottery mini app, RPG Multi-Dice Roller and Rainbow Six Mission Names Generator out of a friend's request, among more serious and complicated projects like a message encoder/decoder and a password scrambler.
You might google for
shuffle algorithms.
Re: Randomness
Posted: 20 Mar 2011 13:29
by Stefan
@tiago,
Test script here >
http://www.xyplorer.com/xyfc/viewtopic. ... 721#p57721
Put any comments please here in this thread.
---------
@Don
First wish:
i could have needed
$OUT = replace( $IN, "x", 1 ,
occurrence=1 )
to replace only the first found occurrence from input, instead of all.
Would be nice if we had the free option to replace only occurrence number X (like in my example above)
but even an flag to just stop after replacing first occurrence would be nifty.
Original function:
replace(string, search, replacement, [matchcase])
Idea:
replace(string, search, replacement, [matchcase,
occurrence=0 for all OR 1 for first OR 2 for second])
Or:
replace(string, search, replacement, [flac])
0: A=a [Default]
1: A<>a
2: stop after first replace
give us: 0,1,2,3
@Don
second wish:
recase(string, [mode], flags)
mode:
toggle: lower to upper / upper to lower
.
Re: Randomness
Posted: 20 Mar 2011 13:41
by tiago
"You might google for shuffle algorithms."
Outside XY I already have my set of tools that perform the task.
I'm just trying to port my solutions into XYplorer language so I can have a flexible tool to deal with instead of launching or creating small apps externally to clutter my desktop with, not to mention the gain of time this could be.
@Stefan
I'll check it out and report anytime soon, not having the "scan for directories" function for that little script you brought us left me with a broken leg for all of this time. I tried to build a complex regex but I am definitely not a good regex'er yet.
So thank you.
Re: Randomness
Posted: 20 Mar 2011 13:59
by tiago
I can't believe my eyes, you made it...
The 690SR8GQ3 YVI57 > 6,9,0,S,R,8,G,Q,3, Y,V,I,5,7 part should not be random and preserve any spaces in between as specified, but from what you've done perhaps I can learn a thing or two and achieve what I want. Once again, thank you (x1000, since this was buggering me because without it I was having limited functions in three or for scripts).
In the previous post I thought you were mentioning the other thread about finding directories then write reports, sorry about the confusion. Keeping my eyes open for that.
Re: Randomness
Posted: 20 Mar 2011 14:26
by tiago

Don't bother, Stefan, disabling a line where it reads "Don't modify code below" allowed me to do what I need.
lol
TY!
Re: Randomness
Posted: 20 Mar 2011 15:00
by tiago
I have a small script that is a kind of "uniqueness/randomness analyzer" that is telling me that everything is perfect, Stefan. I'm intrigued by the fact that your script has reached a maximum rate of uniqueness also in the sense that "random = avoid similar letters as neighbors", as in "a,A,...G,g,...B,b,..." and so on. One chance in five your script has only one pair of similar letters, which in my design is great. Guessing if by your solution's structure I'll be able to reduce such occurrences to zero.
Re: Randomness
Posted: 20 Mar 2011 16:37
by admin
First wish ok, done.
Stefan wrote:second wish:
recase(string, [mode], flags)
mode: toggle: lower to upper / upper to lower
.
You mean toggle each char?
Re: Randomness
Posted: 20 Mar 2011 17:08
by Stefan
admin wrote:First wish ok, done.
Stefan wrote:second wish:
recase(string, [mode], flags)
mode: toggle: lower to upper / upper to lower
.
You mean toggle each char?
Yes.
The whole string, same as with "lower" and "upper"
recase( "XYplorer", "toggle") ==> "xyPLORER"
recase( "A", "toggle") ==> "a"
recase( "a", "toggle") ==> "A"
recase( "CaMeLcAsE", "toggle") ==> "cAmElCaSe"
Thanks
Re: Randomness
Posted: 20 Mar 2011 17:18
by admin
OK; I already did it as you hay have seen. I just called it "invert" instead of "toggle".
