# How do I create probability?

Get help using Construct 2

### » Wed Feb 24, 2016 9:44 pm

Hello,

I'm building random levels generator, and I wander how can I create probability of spawning something; should I do it this way, or is it not probability: random (100), is between num A and B ( ex. 30, 70 )? I'd also would like it to change throughout the game. Any thoughts?

Thanks
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203

### » Wed Feb 24, 2016 10:00 pm

You're on the right track. If you want to change it, use variables instead of fixed numbers in place of A and B, you can change those variables in any event.
B
60
S
30
G
132
Posts: 1,932
Reputation: 74,341

### » Wed Feb 24, 2016 10:00 pm

You could do that. If it's just a probability of happening or not you could just compare with one value.
aka random(100)<40 for a 40% chance.

If you want a probability of more than two things happening you would store random(100) in a variable first. So for example you want A to have a 30% chance and B a 10% you could do:

global number rand=0

every tick
--- set rand to random(100)

rand is between 0 and 30
--- do B

rand is between 30 and 40
--- do B
B
100
S
38
G
134
Posts: 5,555
Reputation: 85,323

### » Thu Feb 25, 2016 12:19 am

Cool, thanks for clarification.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203