Formula, multiples of random number

OK, using a custom hit and damage formula, I ran across a slight roadblock.

Without getting into massive details, basically I have a skill that does a random amount of damage, 1-4, per caster level. I have it set up to generate a number from 1-4 then just multiply this by the level.

The problem I realized is that it can't generate a "real" random number after level 1. As in, at level 1 the damage would be 1,2,3 or 4, but at 2 it can really only generate 2, 4, 6, or 8... but it can't gve 3,5 or 7. And the higher the level the bigger the gap gets.

Is there any way, instead of generating a 1-4 and then mulitpling it by the level, to tell it to generate 1-4 per level then total those, so I can get a more accurate real random damage?

Thanks
The following should work:

Code:
d = 0; a.level.times {d += (rand(4)+1)}; d
Alternatively, I think the following would also work, but I'm questioning my math for some reason this morning. It's a little more efficient.
Code:
rand(3 * a.level + 1) + a.level
Wow, awesome, that seems to work!

Thank you so much!

I'm using the second formula (because I can wrap my brain around the math there 😛 ), and it 'seems' to work so far.

****

As a side question, I assume the '3' is what I would change if I want a similar skill with a higher upper limit? As in, 1-6 the 3 would be a 5, 1-8 the 3 would be a 7, etc...?
Exactly. You would change the + a.level at the end if you wanted to change the lower bounds; you'd need to lower the "3" in that case. So a range of 3 to 5 would be

rand(2 * a.level + 1) + a.level * 3
It is actually more accurate to say the "3" is range of variance if you will.
OK, first of all , that second formula you just gave me per-emptively solved a problem i didn't even realize I would run in to, basically, if I used a formula for damages that didn't have a starting minimum of 1. So thanks again.

But just I'm sure I understand the formula...

The 3 in the first one, or 2 in this one, is like you said the variance I want. -1 to adjust for the a.level which has to be at least 1, correct?

And the 'a.level * 3' is for the minimum value at level 1 of the damage range, of 3-5 in this case. Also correct?

So if I wanted a skill to start at 2-8 at level 1 it would be....

rand(6 * a.level + 1) + a.level * 2
Sounds like you understand it, but I'll break the formula down into words instead of numbers just to be sure.

rand((maximum_dmg - minimum_dmg) * a.level + 1) + a.level * minimum_dmgSo plopping in the various examples we've used throughout the thread:
Code:
1-4: rand((4 - 1) * a.level + 1) + a.level * 13-5: rand((5 - 3) * a.level + 1) + a.level * 32-8: rand((8 - 2) * a.level + 1) + a.level * 2
If it's easier for you to read and edit, you can certainly leave it in this format here. Just make sure you have a space after the subtraction symbol.The +1 exists just because of the way rand works. By default, rand(10) would return a number between 0 and 9. In this case, we want a number between 0 and 10.
Ok, well thanks again.

That 'word formula' really helps a lot! Makes the numbers a lot more clear. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/formula-multiples-of-random-number.23288/