Randomness

Features wanted...
tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Randomness

Post 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.
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: Randomness

Post 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>";
Power-hungry user!!!

j_c_hallgren
XY Blog Master
Posts: 5824
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Randomness

Post 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
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: Randomness

Post 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)
Power-hungry user!!!

admin
Site Admin
Posts: 60561
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Randomness

Post by admin »

Look at rand().

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: Randomness

Post 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.
Power-hungry user!!!

admin
Site Admin
Posts: 60561
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Randomness

Post 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.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Randomness

Post 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

.

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: Randomness

Post 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.
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: Randomness

Post 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.
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: Randomness

Post by tiago »

:P
Don't bother, Stefan, disabling a line where it reads "Don't modify code below" allowed me to do what I need.
lol
TY!
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: Randomness

Post 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.
Power-hungry user!!!

admin
Site Admin
Posts: 60561
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Randomness

Post 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?

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Randomness

Post 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

admin
Site Admin
Posts: 60561
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Randomness

Post by admin »

OK; I already did it as you hay have seen. I just called it "invert" instead of "toggle". :)

Post Reply