Question about "Random"

Just started using Construct 2? Post your questions here

Post » Thu Jan 08, 2015 2:36 am

Hello, I'm trying to set a random number from a range of 1-4 when you collide with a power-up. How do I do this? (as far as I know, all random ranges must start from zero?) But i know there must be a way.
B
4
Posts: 27
Reputation: 254

Post » Thu Jan 08, 2015 3:06 am

random starts from what you want it to and ends where you want it to. What you want is "random(1, 4)". This will give you a number in between 1 and 4.
ImageImage
B
49
S
15
G
2
Posts: 270
Reputation: 6,679

Post » Thu Jan 08, 2015 4:32 am

Actually, if you want integers, you want: int(random(1,5)), or you can use choose(1,2,3,4). The manual explains the subtleties of the two random() commands.
https://www.scirra.com/manual/126/system-expressions
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Thu Jan 08, 2015 4:49 am

thank you guys! i'll try this stuff out.
B
4
Posts: 27
Reputation: 254

Post » Thu Jan 08, 2015 7:48 pm

blackhornet wrote:Actually, if you want integers, you want: int(random(1,5)), or you can use choose(1,2,3,4). The manual explains the subtleties of the two random() commands.
https://www.scirra.com/manual/126/system-expressions


Oh, and you can always use round(random(1,4)) as well. I had no idea there was a choose() function though, thank you!
ImageImage
B
49
S
15
G
2
Posts: 270
Reputation: 6,679

Post » Thu Jan 08, 2015 9:32 pm

round() won't give you an even distribution of numbers. It's better to use int() or floor() (same thing).
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests