# Random Subtraction

### » Sat Mar 19, 2011 1:09 pm

I'm making a shooting game and all I need to know is how to set the damage (which is a private variable) of the bullet to be randomly chosen between two numbers.
eg. I want my pistol to deal damage anywhere between 1 and 10 how would I do this?
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

### » Sat Mar 19, 2011 1:38 pm

Use this at the subtract on your pvt variable

random(10)

Then to keep it from going lower

Compare pvt variable : less or equal to 0 / set pvt variable to 1
B
23
S
3
G
7
Posts: 1,356
Reputation: 7,676

### » Sat Mar 19, 2011 1:41 pm

You can use the Random(x) expression to get a random number. To get a number within that range, you would subtract from your private variable -- using the subtract from private variable action -- this expression:

Random(10) + 1

One thing to know about the Random(x) expression is that it returns one of x possible numbers, from 0 up to, but not including, x. So Random(10) will return a value in the range of 0-9. Thus, adding 1 to this will bring the minimum up to 1 and the maximum to 10.
Moderator
B
115
S
41
G
20
Posts: 1,586
Reputation: 19,196

### » Sat Mar 19, 2011 1:53 pm

Aah i forgot about the +1 at the end.
B
23
S
3
G
7
Posts: 1,356
Reputation: 7,676