List Randomizer

Have you ever wanted to randomize the items on a list? Now you can with this custom block! Just put the list in its spot, then put the number of times you want to be randomized! I'll make updates along the way.

You don't have to use INDEX OF to find out where TEMP is; it's at position RAN in the list! :~)

Instead of making a lot of moves from one random position to another, the canonical algorithm for shuffling a list is more systematic:

  1. Pick an item at random and move it to the front (item 1) of the list.

  2. Now that element is in its final position! So just shuffle the items from position 2 to the end.

  3. Then from 3 to the end, and so on until you run out of items.

Building on @bh’s approach I built both a recursive and an iterative implementation.

First, recursive:

(BTW I used LET, which is a combined creation and (one-time) assignment of a variable)

It works quite well, except for really large lists (on my machine, a list with 20k elements will generate a range error).

Therefore I also made a (perhaps slightly less elegant) iterative version with in-place swaps:

The latter is almost 5 times as fast as the recursive version, and suitable even for very large lists.

I have made a v2! A lot shorter, and hopefully faster!

Honestly, you couldn't have put that in a more respectful way, yet feel absolutely disrespected.
Not sure how that's possible but it is.
I was just supposed to be simple, and easy to understand. It's what came to mind first, and like chess, most of the time, the first thing to come to mind, isn't the best. But ignoring the 4 IF blocks, it's honestly really shortcode.
I'm glad I got corrected for my mistakes and will learn.
I'll now go work on a v2 of some sort.

Oh, I'm sorry! That wasn't my intent at all.

One of my weaknesses as a teacher is not knowing when not to teach someone something. Especially in computer-mediated teaching where I don't really know you and also can't read your body language. I'll try to get better about that.

Oh, it's absolutely fine. I knew that you just inform me, but.. I should say that I felt disrespected, although it wasn't disrespectful at all. All apologises accepted! =]

And my comment about this is that I felt disrespected because of "noo you dont wanna do THIS, that's sooo inefficient, do this"

But I know you didn't mean that at all. I'm quite glad you did say what you did because I learned that what I did wasn't the best, and made a v2 based on what you said! Really greatful, so thanks!

You're welcome!