% chance of certain array values?

Hey guys!

I was wondering if there was an efficient way of creating various % chances of certain variables being selected within an array.
Here is an example of what i have so far:

What I am hoping to achieve is to have, lets say integer 3 have a lower % chance of being selected than the other integers within the array.
Is there a good way to go about doing this?


Hi Milo

You have something very ‘shonky’ going on there… :slight_smile:

You’re creating a loop every frame that way.

A much better way is to populate the array more with the items you want likely selected and rarely with the ones you want to be rare. Then all you have to do is use a random int on the arrary…

Some more examples here:


I like using select nodes so you do not need an additional array:


You can even plug another random generator into each Option:


I don’t remember who here on the Answers Portal suggested that some time ago, but one great and effective way of doing such things is using a custom curve. If you need 1%, you can create such curve:

There are 2 keys: [0; 0] and [0.99; 3]. Then you create a Curve variable in your BP and select this curve. Next you do this:

And it will return 3 with 1% chance, and [0-2] with equal chances. What is great in using curves, it’s a really scalable approach. In future, is you want to change the chances, you won’t have to do anything in BP; just change the curve or create several curves and interchange them at will.