[Solved] Generate Random points in a Circle Uniformly

0 favourites
  • 6 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • I saw the manual.

    random(a), goes from 0 to a without choosing a.

    random(a,b), goes from a to b including a.

    What I need in random(a,b) including both a and b.

    random(0,1) or random(1)

    Goes from 0 to 1 including both 0 and 1 in its selection.

    Edit: Changed the title to make it much more clear.

  • While it never is 1 exactly, it can be pretty close. ex: 0.99999999999 which is practically 1.

    Do you have a use case in mind? I've only ever needed 1 included if the number was an integer.

  • I am trying to implement an algorithm that spawns sprites in a circle randomly and uniformly decided by its radius. The 1 would allow the angle to be 2pi.

    function getRandomPointInCircle(radius)
      local t = 2*math.pi*math.random()
      local u = math.random()+math.random()
      local r = null
      if u > 1 then r = 2-u else r = u end
      return radius*r*math.cos(t), radius*r*math.sin(t)
    math.random() = random float number between 0, 1
    My C2 code: t is replaced with q
    All I get is this:
    When I want something like this:
  • C2 uses degrees instead of radians so t should be 360*random(). With 2pi it would only be about 6 degrees which is what your first pic looks like.

  • Circle.capx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • korbaach Thanks. Ill see if I can implement this into what I already have.

    R0J0hound Thanks for letting me know that C2 doesn't use radians.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)