Making a Weighted Random Float Generator?

First off I’m not doing any coding, everything is in Blueprints. I have no problems (obviously) simply getting a random float in range, but the problem I am running into is when I want an Intelligence Stat to come into decision making for AI.

Generally I would use the Weighted Bool, but say I want the Intelligence Stat (1 to 100) to decide the weight of a float between say, 0 and 800. So an Intelligence closer to 100 would return values closer to 800 more frequently, and values near 0 less frequently.

Been doing some google searching and I haven’t found much beyond people basically needing the Weighted Bool.

Anyone have ideas?

Hi man , you could

vary the number of called out “random in range” for example, casting 100 random in range from 0 to 1
will give you a stability to 50%

or you could use “lerp” the random value to the high value giving you greatest bonus for most distant numbers like
like , 10 will get a bonus of 10 while 90 just 1

or you could just add a bonus float random in range to add to your first random call, and then clamp it to the max
so you will shift your probability toward the max.

you could also check for some statistics and probability theory if you need something like casino-proof

I know I’m like almost 7 years late on this, but it still pops up on google searches, so hopefully, this will help someone.

I made a function for a random weighted float generator which could be used to extrapolate to other number generators.

This may not look the most elegant but I’m basically chaining the random generators to make the weighting distribute stronger to one side or the other of a specified range and the number of chain links is determined by the input variable, similar to a weighted boolean.



In the images, you can see that I weight the random float stronger toward the min or max based on its distance from 0.5 in either direction.

Weight 0.5->0 = Stronger weighting toward the Min.
Weight 0.5->1 = Stronger weighting toward the Max.

And I branch the execution based on whether the weight is >= or < 0.5.

This works as a pure function too. Hope I can help someone!

EDIT!: Change the branch bool to a greater equal, NOT less. Sorry.

2 Likes