On 23/10/26 at 17:36, Greg Wooledge wrote:
>> I've added the "if [ -z "${assigned[rand]}" ]; then" statement because $rand
>> had many occurrences of the same value so I tried with the "assigned[$rand]"
>> array to avoid that, looping in the circumstance "$rand" had a value already
>> assigned.
> It's*fine* if rand gets the same value more than once in this loop.
> It just means that particular slot in the playlist will be swapped
> more than once. It doesn't mean a song will be repeated.
In my understanding I supposed that some clip was left in its original position (skipped) but now I realize that it is not possible because "$i" changes for each iteration.
>
> I suspect you don't understand what the original code is doing. I added
> the comments for a reason -- they tell you what each section does.
> I didn't explain every line, because that's not how code comments should
> be used.
I had my coding in my mind. That it encompassed an unique $rand value necessary as array index to shuffle the playlist[], as I did in my previous coding. In other words I did a sort of confusion mixing my previously coding concepts and apply them to your code.
>
> If you need help understanding the original code (e.g. an explanation
> of every single line, one by one), feel free to ask.
>
> Are you stuck on the word "shuffle"? It's normally used with a deck of
> playing cards. If you have a deck of cards, and you shuffle it, then
> the same cards are still in the deck, but they're in a different, random,
> order. You don't magically get two of the same card, unless your deck
> started out with duplicates.
No, I'm OK with the "shuffle" meaning.
>
> That's what this loop is doing. It takes your array of filenames and
> shuffles it. The filenames are randomly re-ordered.
I apologize for the noise, but since I was unsure, I decided to write you an email, I'll restore the code to its original state.
Kind regards,
--
Franco Martelli