# [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
end
[/code:1bx258wg]
math.random() = random float number between 0, 1

My C2 code: t is replaced with q
[img="https://i.gyazo.com/689198444e1b138b38fe3066f423ce13.png"]

All I get is this:
[img="https://i.gyazo.com/fb9ae2e2c42ff82650b66c81f32003bf.png"]

When I want something like this:
[img="https://i.gyazo.com/14aba38b587da1fd607060dc12f66e22.png"]``````
• 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.

• ## Try Construct 3

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

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.

• 6 posts