Unity Random Point Outside Camera

First we will get the x, y coordinates of the camera relative to the Viewport this will ensure that we'll have the edges of the camera view no matter the aspect ratio of it.

Ps. I use this Range struct just because i prefer to read min, max instead of x, y in this situations where i have a min, max value.

[System.Serializable]
public struct Range
{
    /// <summary>
    /// Returns a random value between min and max.
    /// </summary>
    public float Value { get { return Random.Range(min, max); } }

    public float min;
    public float max;

    public Range(float min, float max)
    {
        this.min = min;
        this.max = max;
    }
}

public static Range VerticalLimit;
public static Range HorizontalLimit;

public static Camera MainCamera;

private void Awake()
{
    MainCamera = Camera.main;

    Vector2 __minLimits = MainCamera.ViewportToWorldPoint(new Vector2(0.0f, 0.0f));
    Vector2 __maxLimits = MainCamera.ViewportToWorldPoint(new Vector2(1.0f, 1.0f));

    VerticalLimit = new Range(__minLimits.y, __maxLimits.y);
    HorizontalLimit = new Range(__minLimits.x, __maxLimits.x);
}

Then we randomize if the point will be on the horizontal or vertical axis, if vertical for example we than randomize which side of the vertical spectrum top or bottom (notice that i multiply the choosen axis by 1.1f, so that the point is outside of the camera view) and than we randomize a value between horizontal min and max.

public static Vector2 RandomOutside()
{
    float __x, __y = 0;

    if (Random.Range(0, 2) == 1)
    {
        __x = Random.Range(HorizontalLimit.min, HorizontalLimit.max);
        __y = Random.Range(0, 2) == 1 ? VerticalLimit.min * 1.1f : VerticalLimit.max * 1.1f;
    }
    else
    {
        __x = Random.Range(0, 2) == 1 ? HorizontalLimit.min * 1.1f : HorizontalLimit.max * 1.1f;
        __y = Random.Range(VerticalLimit.min, VerticalLimit.max);
    }

    return new Vector2(__x, __y);
}