# Calculating a value based on a weighted element within bounds?

I’m trying to write a script that will allow a game object to move in a general direction within specified bounds rather than in a specific direction. Based on what I’ve seen with the function LerpAngle, the angle portion won’t be particularly difficult I think. It works by using a minAngle and maxAngle and interpolating between them based on a value “t” that must be between 0 and 1 inclusively. If t is 0.5, it will return the exact midpoint of the two angles; if it is 0, LerpAngle returns minAngle, and if it is 1, LerpAngle returns maxAngle.

I’ll have the ideal vector (calculated elsewhere and already working) which will be identical to the midpoint, and I’ll be able to treat minAngle and maxAngle as a +/- threshold from this ideal midpoint.

What I’m trying to do is programatically calculate a “t” value based on an “amplitude” variable.

When the amplitude is 0, t is calculated completely randomly. IE values should be effectively indistinguishable from the performance of t = Random.Range(0f,1f);

When the amplitude is 1, t = 0.5 no matter what.

When it is any value in between 0 and 1, I’d like it to sort of be a gradient that plots like a progressively more narrow bell curve from 0 to 1.

Rough sketch of expected performance -

I’m not really sure how to implement this, but it seems like something that might already have a library function somewhere - if not necessarily unity. Can anyone either point me in a helpful direction for writing it myself, or towards an existing function that does something similar?

With the help of a friend I was able to figure out that the concept I’m referring to here is Normal Distribution and Random Gaussian Variables.

I don’t have a working implementation yet, but based on what I’ve found so far a “Box-Muller Transformation” keeps coming up and seems like an effective direction to go in.

Hopefully this will help point anyone else with this issue in the right direction as well.