# How do I set random and min expressions together?

Get help using Construct 2

### » Mon Aug 18, 2014 7:56 pm

Hi guys. I want to make random movement of sprite in x axis. Can I use random and min expressions together?
How the expression need to look like?
I want random(317, 700) and something to set minimal distance sprite to move.
B
4
Posts: 8
Reputation: 218

### » Mon Aug 18, 2014 7:59 pm

Maybe I misunderstand, but the minimal distance of the movement already is 317. The method looks like this: random(minimum, maximum).
B
13
S
2
Posts: 21
Reputation: 721

### » Mon Aug 18, 2014 8:08 pm

You know if I set only random from(317, 700) then its possible that 1st time the x position is 317 and next time 400 what i dont need. i want to set minimal distance between those random x. if you know what i mean.
B
4
Posts: 8
Reputation: 218

### » Mon Aug 18, 2014 8:10 pm

that it doesnt create random x from time to time with distance smaller than 100px for example.
B
4
Posts: 8
Reputation: 218

### » Mon Aug 18, 2014 9:29 pm

Ok here's a pretty dirty way to do it:

randomAndMinExpressions.jpg

So basicly it says: when a certain event is triggered (in this case a button is clicked), it sets a group active and in that group it generates a random number between 317 and 700 at every tick. Then it checks in the subevent if that number does NOT lie between oldLocation-100 and oldLocation+100 (meaning: it does NOT lie within range of 200px of the oldLocation). So if that's the case, it sets that good number as newLocation AND oldLocation, generates an object at that location and sets the group inactive. Until you click the button again.

I'm sure the more experienced guys here can provide you with a better solution because this is probably not that good performance-wise.
You do not have the required permissions to view the files attached to this post.
B
13
S
2
Posts: 21
Reputation: 721

### » Tue Aug 19, 2014 6:05 am

That's what I wanted to know!
Thanks man for your time and work!
B
4
Posts: 8
Reputation: 218