How to avoid specific value in random array after another specific is called?

You can see in image I am getting three random values.

SP stands for spawn point

What I want is

If function returns value Right SP then I dont want its next value to be Left SP. (It should be either Front SP or Right SP)

And If function returns the value Left SP then I dont want its next value to be Right SP. (It should be either Front SP or Left SP)

How to do that? I don’t have any experience with C++ and I just started blueprints few weeks ago.

I would have search the solution. But I don’t even know what to search.

You just have to code it specifically.

As ClockworkOcean said, you have to do it specifically as there is no build in way.
Basically, you would have to store which value was last and then either remove next one from the array before randomization or use randomize until you get different value than the next one.

Based on your question, you want a function that returns a random value, the next time it’s called, it will return another random value, but not next in order.

Here are two fundamental approaches to get you started, they are not really optimized and the first one is pretty error prone.

When using unreal’s random, be aware of using both of it’s outputs at once (value/index), as it is a pure function, so it may/will be called twice and you will get two different values.

Thanks for this. I didn’t understand most of it as a absolute beginner. But I tried replicating this and got error

The type of the parameter for the function is undetermined. Try selecting the function node and setting it’s parameter type to the one you are using.

By the way, it’s better to spend more time trying to understand something chunk by chunk rather than just copying it (IMO, it’s one of the best advices I could get)

If function returns value Right SP
then I dont want its next value to be
Left SP. (It should be either Front SP
or Right SP)

Wouldn’t it be easier to remove the array element after using it:

If you remove it, you can’t possibly get it again.

And you could also work on a copy of the array if you ever want to restart the randomisation from scratch. Ideally, one would add an array bounds check here.

This was too complicated for me so I extended my flat cube geometry platform instead. The previously had only one cube. So spawning with front SP and then Back SP would overlap the first and third cube along z axis. So I simply added few more cubes, shifted spawn points and also added rotational transform to create more randomness. Thanks for your help though. Your solution will help me if I encountered into such issue again.