Once again, something for which a new operator would be perfect as this is just a few lines of C++…
This would actually be a quite useful feature.
With the current TT operators you could implement something like the Fisher-Yates_shuffle but you’d need another script dedicated to that as it won’t fit in one loop line (I could only get it down to 40 characters) :
This is totally untested as I’m nowhere near my Teletype, so probably not working . And it uses a ton of variables, so not super nice for complex scripts.
[where you want to shuffle the array]
P.N 1; A 4; B 12 L A - B 2: C I; SCRIPT 1
[in script 1]
D RRND C - B 1; X P C; P C P D; P D X
The first line initializes things :
- we work on pattern 1
- A defines the first index that we want to shuffle and B the last one (in that case from the 4th index to the 12th)
Then we loop over the desired indexes, store the I value in another variable as they are script-dependent and call the desired script (loops working on several lines would make that much less cumbersome). We use script 1 here but it can obviously be any other one.
In the other script, we get a random index in the desired range and then the second line swaps both array elements using a buffer variable (in that case X).
As I said, that’s probably not functional as it’s untested but something like this should basically work.
And an operator for that would be great .