2D Array Shuffle

3

Attached Files

The following files have been attached to this tutorial:

.c3p

2darrayshuffle.c3p

Download now 83.64 KB

Stats

206 visits, 278 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 16 May, 2024.

Currently, The Vanilla Array sorting is 1D mode, for 2D arrays it breaks their relationship. For some configuration sheet this does not apply.

Therefore, when we sort, we should randomly get their order index, and then move the original array from this order.

Use advanced random addon to create a random order for each row, and then use a Temp array for data exchange

Step 1

AdvancedRandom: Create permutation table action

It can generate a string of random sorting numbers. For example, When you fill in 10 as the length, it will return numbers 0-9 that have been randomly shuffled. If you want it to be 1-10 instead of 0-9, then you can set offset to 1, which means shifting forward by 1 number value.

You can see the shuffled order in Debugger

Then use AdvancedRandom.Permutation(index) expression to get this order. For example, use AdvancedRandom.Permutation(1) can get its 2nd value, which is 3.

If you want to loop through the entire list, you can use a For loop.

Step 2

Now that we have this new order, we can use this order to find the item in the array. use Array.At(x, y).

For example,

Apple 100
Banana 50

get the value of the original array

Array.At(0, 0) -> Apple

Array.At(0, 1) -> 100

Through this order, find the data of the new row

order = AdvancedRandom.Permutation(index)

Array.At(order, 0)

Array.At(order, 1)

Step 3

EventSheet:

.C3P

2darrayshuffle.c3p

Download now 83.64 KB
  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • this is excellent. i tried to get this to work with more than 2 items (on the y axis), but failed. is it possible for you to update/add a new tutorial for tables with more than 2 items in the Y axis?