# How do I create probability?

0 favourites
• 4 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
• 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

• 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.

• 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

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Cool, thanks for clarification.

• 4 posts