Shuffle is not always shuffling last index


I don’t trust my luck to be that stellar to get the same last index over and over, so I assume there is a bug with the last index?

Around half the time the last index is the same before and after shuffling.

My script is very simple, i generate a big list of numbers and shuffle them, then print them.

Fun huh? :slight_smile:

Hi ,

Does this occur in a clean, blank project with no additional content or is it limited to one project? What steps can I take to reproduce this on my end?

Hey ,

This is a Clean project :slight_smile:

Have you tried to repro the script as seen in the Shuffle_00.Jpg I posted ? Because this is as easy as it gets. Just do that script in a pawn blueprint and voila

Hi ,

Yes this was the method I attempted and on my end all indexed items shuffle. I then attempted a variant where every time I pressed 1 it would shuffle and print the index with the same results. Each time the indexes shuffled as expected without missing any indexes. Are there any other steps I can take to reproduce this?

hum ok. This is odd.
I’ll submit a clean project then.

There you go.
I usually run 4 clients at the same time to test the issue. Sometimes it won’t happen sometimes it would happen on 3 clients out of 4.

link text

Hi ,

On my end, all 4 clients have consistently randomized the shuffle of indexes entirely each time the script is run. Is it possible that during the shuffle the last index just happens to retain it’s position every once in a while? That is still a possibility within a shuffled array.

okay now i’m baffled… how come I get a not so random result while it’s fine on your end on the same project?

I mean once a while yeah sure, but look at that screen for instance 3 out of 4, it’s almost one in a million chance:

Try this - Place your shuffle and print information on button input 1. Once that is done, go into each client and press 1 to see if they come up the same or similar each time. Do this a few times and see if you get the same results as you were before.

Same problem. The last Index stays the last quite often.

The only thing I’m seeing is that all clients are producing their numbers the same on all 3 other clients, which is expected. Are there any other steps I can take to reproduce this on my end? Perhaps try clearing and re-sizing the array before shuffling.

Well I tried to clear the array, resize and resuffle and I get the same issue.
The list is random for everybody, except for the last index.

I tried to execute that script when pressing a key, And it does the same problem, sometimes it’s fine sometimes the last index of the array is not shuffled or the randomness is resulting it as the last index.

Try to add a key shortcut in the blueprint to reshuffle the list (don’t forget to clear the array first) and see if you can reproduce the problem.

Just tried with a list of 500 indexes, and it’s the same problem… 500 is being the last index quite often… I even got it 4 times in a row ! The odds are 1/62 500 000 000… There is definitively something wrong, and I’m really surprised you can’t repro it with the exact same project.

Hi ,

While I wasn’t able to reproduce this on my end, I went ahead and entered a bug report, UE-21891, to be assessed by the development staff.


Awesome ! Let me know if you get any information on that. This is pretty important for my project. Thanks.

ps: I might not be the only one with that issue, I don’t know if thoses posts are relevant. It seems there are different results when testing in-editor and StandAlone/Packages

link text

link text

link text

Hey ,

I created another project with a script that would do a shuffle with a loop, and show how many times an Item appeared at a certain Index after being shuffled.

Here are the results

After 85k loops, the results speak for themselves. Everything seem to be fine and are in the correct range, except for the last index.

ps: The shuffle is using a copy of the original array, it’s not using the same shuffled array over and over.

It is noteworthy that the Last index of an array has (as expected) greater chances to be the last index after a shuffle, and lesser chances to be the first, in a linear way.

Actually all of the rows have a linear tendency with a peak at i-1, and after that everything back to normal (except last id of course because of the last element)
(Sorry, didn’t want to make it unsolved)