Replace value at random index

Hi all, I’ve been trying to make a graph that will replace values in a list at random. For instance if I have a list of 5 "A"s, I want the graph to replace 2 of them to “B” at a random index.


  1. A to 0. A
  2. A to 1. B
  3. A to 2. A
  4. A to 3. A
  5. A to 4. B

I’ve tried the “math.random” node with “math.remap” (between 0 and 4 for the above example) then “round” to specify random index to replace but sometimes this produces duplicate numbers (since for example 1.674 and 1.832 both round to 2). Thus only replacing one letter, not two.

If this can be solved, I’d then want to replace another two in the next phase of the graph, but only from the "A"s:

  1. A to 0. A to 0. B
  2. A to 1. B to 1. B
  3. A to 2. A to 2. B
  4. A to 3. A to 3. A
  5. A to 4. B to 4. B

Sorry , as I’m not in office I can’t post WIP graphs but hopefully the above information is adequate to get some helpful pointers on how I can solve this

HI @Andy_Grout,

You can do an If statement to replace only 2 of them with B.

For the second part, you can continue with a second if statement :

Thank you Alban,

The method to use “List.IndicesOf” along with archilab node “Lists.ReplaceItemAtIndex” was exactly what I was after. I’ve rearranged a bit (particularly where the shuffle node takes effect) to ensure the elements in original list remain in their corresponding index at the end:

I can now package this up into a more concise custom node. Really appreciate the help!