# Geometry Nodes: How to randomize/shuffle indices in 'Distribute Points on Volume'?

I have this Geometry Nodes setup:

But the indexes are like this, even if I use a random seed for the Distribute Points node at the volume:

How to obtain truly randomized indices?

(In order to view the indices, I used this GN modifier on top of my first GN modifier: https://artofriaz3d.gumroad.com/l/indexviewerfields)

$$\hspace{15pt}$$Using sorting nodes like Points of Curve works perfectly and results in simple node trees, but as domain size increases, like thousands of indices and more, sorting will slow down significantly, so if anyone wants faster methods for these cases, I recommend the methods provided in this answer.

# $$\text{Pick Discard Repeat (PDR)}$$

## $$\text{Timing comparison}\\\tiny{_\text{made on my potato laptop}}$$

$$\hspace{15pt}$$2.5 K points

Native Sorting:

PDR Shuffle (4 steps):

$$\hspace{15pt}$$10 K points

Native Sorting:

PDR Shuffle (4 steps):

## $$\text{How it works}$$

$$\hspace{15pt}$$The nodes are separated in three node groups, one which can be chained for more steps.

• PDR Shuffle Prepare

$$\hspace{15pt}$$Generates the initial point cloud storing all indices as available indices. Their positions is set to $$(0, 0, i_{ndex})$$ and their IDs are set to their indices.

• PDR Shuffle Step

$$\hspace{15pt}$$For points in Available Indices, set their ID to the ID of a random point and then, for points with repeated IDs, leave only one per ID by deleting all of the others. After that set their position to $$(0, 0, I_D)$$ and join them to Shuffled Indices before outputting in the Shuffled Indices socket.

$$\hspace{15pt}$$Also for points in Available Indices, remove all points whose IDs had been picked in the process above before outputting the result in the Available Indices socket, this is done using the Geometry Proximity node, which is why point positions are being set to $$(0, 0, I_D)$$.

• PDR Shuffle End

$$\hspace{15pt}$$If any remaining available indices, sort them with random weights ('Native Sorting') and join to Shuffled indices.

$$\hspace{15pt}$$The resulting point cloud is from where ID will be sampled using the index of the current context (The geometry and domain that are using the shuffled indices output).

$$\hspace{15pt}$$ I also added another output called Pointed By, which has the index that got the current index after shuffling.

$$_\text{Blender 3.6 (but can be opened on 3.4)}$$

Update: The Separate and Rejoin method pointed by Robin Betts is many times faster than PDR with hundreds of thousands of indices, since it does not depend on distance calculation nodes like Geometry Proximity.

# $$\text{Separate and Rejoin}$$

## $$\text{Timing comparison}\\\tiny{_\text{also made on my potato laptop}}$$

$$\hspace{15pt}$$100 K points

PDR (4 steps):

Separate and Rejoin (8 steps):

## $$\text{How it works}$$

$$\hspace{15pt}$$Like PDR, Separate and Rejoin operates with three different node groups, one which can be chained for more steps.

• S&R Shuffle Prepare

$$\hspace{15pt}$$Generates the initial point cloud setting their IDs are to their indices.

• S&R Shuffle Step

$$\hspace{15pt}$$Selects random points and move them to the end of the domain, this action is performed by separating them and then appending to the unselected points with the Separate Geometry and Join Geometry node.

• S&R Shuffle End

$$\hspace{15pt}$$From the shuffled points, samples the ID attribute at the current index.

$$\hspace{15pt}$$ The only disadvantage compared to PDR, is that you cannot use Native Sorting to randomize indices that weren't shuffled, the cause is that Separate and Rejoin operates on all points in every step, increasing disorder of all.

• 100K points, 4 steps. (Second image is displaying UV of index which has a shuffled index equal to the current index)

$$\hspace{15pt}$$ But, with Blender 4.0, with Repeat zones, the number of steps could be made to depend on the number of indices.

For me, $$\lceil\ln{T}\rceil$$, where $$T$$ is the index count, already gives a good number of steps. For PDR, $$\lceil\frac{\ln{T}}{2}\rceil$$;

$$_\text{Blender 3.6 (but can be opened on 3.4)}$$

• Great stuff .. I haven't managed to get the separate and rejoin method to be any better than 3x slower than this.. yet :) .. on 10k . And that one's very iteration-dependent. Commented Oct 16, 2023 at 7:34
• Fantastic! This was very easy to use in order to set new IDs in order to randomize my points distributed in the volume mesh. And so nice if it's even more optimized than the other good answer. Great! Commented Oct 16, 2023 at 10:22
• @RobinBetts I made a test right now and one variation of separate and rejoin with 8 steps seems to be about 1.5x faster than PDR (with 4 steps) on my laptop with 10k points. 8 steps were used to get a good random shuffle and remove any visual patterns. I will update this answer later today. Commented Oct 16, 2023 at 14:31
• @Hulifier good spot! I modified my version a bit to make it what I thought would be a bit quicker, using Vector random.. I seem to have made it slower, if you're getting better times. The rejoins are taking most of it, for me. Commented Oct 16, 2023 at 14:45

There is a technique that can be used to re-sort points based on a specific value.

I have called this Native Sorting Technique, because it uses only a small node trick that does not require any quadratic complexity.

It is described in more detail here: How can I re-sort the points/indexes of an object in geometry nodes?.

This post is about the opposite, sorting points, but with the same technique you can also mess up the order of points.

The sorting criterion is crucial here. To achieve a random order, you would simply have to insert the node Random Value at this point.

But keep in mind: A rearrangement of indices is only possible by recreating the object. So the points you created are only used as a starting point, and new points are created instead with the same positions, but only with different indices.

(Blender 3.4+)

How about separating randomly selected points and joining them back?

This reshuffles partially the indices so this process can be repeated multiple times for a good shuffle.

On the figure bellow are shown two objects converted to mesh. The left one has the "Reshuffle point indices" group off - the right one - it is on. Both in edit mode with indices on. A third object shows the simple node setup.

Here is an example blend file:

• This is literally shuffling, and is surprisingly effective, but I'm not sure what's the proper way to test it - the .blend file I linked to checks if the horizontal gradient disappears, but some statistic measurement would be better... Commented Oct 17, 2023 at 19:26
• Exactly. It is like shuffling a deck of cards. Remove 50% randomly selected cards and add them to the top of the deck. With 3 or 4 repeats you get pretty random distribution (gradient completely destroyed). It is important to use different seed. There is a Hurl Noise filter in Gimp that does the same thing. You can try it on grayscale image with gradient. I suppose with Blender 4.0's Repeat node it could get even easier to set up. Commented Oct 17, 2023 at 20:05
• Awesome! This is also very easily understandable for a layman like me :) Simple answers are sometimes the best answers. Commented Oct 18, 2023 at 10:26

I just started thinking, though, that why THIS super-simple answer actually doesn't work for my initial problem? It seems to work, but, is there something I'm missing?

• This can (and very likely will) produce gaps and duplicates amongst the indices. Commented Oct 16, 2023 at 12:52
• @AlpineWorldCup Thank you for the clarification! Commented Oct 18, 2023 at 10:24