# Randomise X location

### » Mon Jun 11, 2012 1:56 pm

I'm trying to spawn clouds on my background at a random X location, where they will then fade in and out over 30 seconds before spawning again. The clouds always spawn in the exact same X position though. Here's what I have for the event:

Every 30000 milliseconds
System: Create object Cloud on layer "Clouds" at (random(1,3000), 790)

Have I misunderstood how the random expression works? I thought that random(1,3000) would make the cloud spawn somewhere between 1 and 2999 on the X axis.

B
15
S
8
G
7
Posts: 256
Reputation: 5,370

### » Mon Jun 11, 2012 2:09 pm

The random function only need one argument(in this case the 3000.) If you want to create something betwen lets just say -50 and 50, you can do it like this:
random(100)-50Pecek2012-06-11 14:10:18
B
10
S
6
G
3
Posts: 127
Reputation: 2,481

### » Mon Jun 11, 2012 3:29 pm

Ahhhh, okay thanks! I have that event set up three times, for three different sections of my level (to keep clouds spread out, and stop a freak occurrence of them all spawning next to each other). So at the moment I have the three X positions as:

1,3000
3500,6500
7000,10000

So if the first one should just be random(3000), how would I calculate the others? The mathematic side of my brain leaves a lot to be desired, so I'm struggling to understand how to adapt your example of random(100)-50

EDIT: Does the -50 part mark the starting point, and the (100) mean how to much to go up to from there? So would my second event be random(3000)6500? I may be completely wrong here.-Silver-2012-06-11 15:33:36
B
15
S
8
G
7
Posts: 256
Reputation: 5,370

### » Mon Jun 11, 2012 3:33 pm

@-Silver-
random(3000) + 3500
random(3000) + 7000
You only have to randomize the differences.:)

Edit: a quick example, look at the first one. You want to create a random between 3500 and 6500. If you do it like this: random(3000) + 3500, and the random returns 20, you will get 3520, if it returns 1500, you will get 5000, and so on.Pecek2012-06-11 15:36:26
B
10
S
6
G
3
Posts: 127
Reputation: 2,481

### » Mon Jun 11, 2012 3:34 pm

Haha, thanks! I updated my reply with a guess, but as I expected, I was completely wrong

Thanks Pecek, much appreciated
B
15
S
8
G
7
Posts: 256
Reputation: 5,370

### » Mon Jun 11, 2012 3:41 pm

That's why the forum for.
B
10
S
6
G
3
Posts: 127
Reputation: 2,481