# [Solved] Generate Random points in a Circle Uniformly

Get help using Construct 2

### » Mon Oct 12, 2015 11:51 pm

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.
Last edited by DurandalCorp on Sat Oct 17, 2015 5:30 pm, edited 1 time in total.
B
5
S
1
Posts: 23
Reputation: 426

### » Tue Oct 13, 2015 12:10 am

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.
B
101
S
39
G
134
Posts: 5,591
Reputation: 85,520

### » Wed Oct 14, 2015 8:41 am

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.

Code: Select all
`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)end`

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:
B
5
S
1
Posts: 23
Reputation: 426

### » Wed Oct 14, 2015 10:01 am

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.
B
101
S
39
G
134
Posts: 5,591
Reputation: 85,520

### » Wed Oct 14, 2015 1:07 pm

B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

### » Sat Oct 17, 2015 5:31 pm

@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.
B
5
S
1
Posts: 23
Reputation: 426