How do I.... random number but in 50 increments?

Get help using Construct 2

Post » Sat Sep 07, 2013 1:43 am

How do I have a random number between 100-600 but in increments of 50?

Currently I have: (random(round(100*0.05),round(600*0.05)))*150
but this is wrong.
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Sat Sep 07, 2013 1:44 am

int(round(1-6)*100)
B
42
S
17
G
17
Posts: 2,247
Reputation: 17,461

Post » Sat Sep 07, 2013 1:58 am

Hmmm.. Doesn't seem to work. What I'm trying to do is spawn an object with X and Y coordinates. The suggestion doesn't seem to create random numbers between 100 - 600 in increments of 50. Instead, it seems to be subtracting 6 from 1 and then multiply by 100 every single time.
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Sat Sep 07, 2013 3:17 am

int(random(0,11))*50 + 100
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Sat Sep 07, 2013 4:12 am

@jook00
To explain @backhornet 's correct help a bit more: In cases like these just think about what you're trying to achieve mathematically.
100 to 600 in 50's increments.
range you need: 600 - 100 = 500
steps you need: 500 / 50 = 10 => + 1 = 11 (the incremments plus starting at zero)
producing 11 numbers from 0 to 10 inclusive: int(random(0,11))//or shorter: int(random(11))
random(0, 11) produces floats that are higher than 0 and lower than 11, e.g. 0.023 or 10.98
int() omits the fractional part => 0.023 becomes 0, 10.98 becomes 10
0 to 10 * 50 => a range of 500 in 50's increments
+ 100 => shifting to the desired start value of 100
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279


Return to How do I....?

Who is online

Users browsing this forum: DharmaOne, namaewayukidesu, nirwan1911 and 10 guests