% 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?

Thanks!

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:

https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/1381356-random-generation?p=1381535#post1381535

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

292595-annotation-2019-11-18-194716.png

You can even plug another random generator into each Option:

292596-annotation-2019-11-18-194926.png

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.

2 Likes