Search Unity

Feedback Why isn't there a Random.onUnitCircle method?

Discussion in '2D' started by Peter77, Apr 19, 2022.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,610
    I was reading your blog-post that highlights the
    Random
    API and noticed there is no
    Random.onUnitCircle
    method and I wonder why that is?

    upload_2022-4-19_18-26-53.png
     
    OBiwer likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,700
    Probably because you can instantly get it just by normalizing the result of insideUnitCircle.
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,610
    I see, let me rephrase the question: Why is there a
    Random.onUnitSphere
    but no
    Random.onUnitCircle
    method.
     
    OBiwer likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,700
    Could be a million reasons. Here's one:

    - in year X1 some guy wrote onUnitSphere and insideUnitSphere

    - in year X2 another guy wrote insideUnitCircle

    APIs are rarely planned out and written in a single day.

    For instance, look at the .rotation and .rotationUniform properties.

    If .rotation ISN'T uniform, then what is it? Docs say it randomizes the x,y,z eulers, which naively you might think is uniform, but due to pole pinching / gimbal lock is anything but uniform.