I would not define minDamage and maxDamage when generating the item at all. Your goal is to find minD and maxD, but it is important to realize that there is single damage number(in your case, as you said its linear scaling with level).
You know the damage is linear: damage = scaling_factor * item_level
. For example scaling factor of sword might be 2, for dagger 1.5 and for two-handed axe it is 3. Also note I used item_level
, if you want to have different quality items it might be a good idea to separate required level and item level(but you probably do that already).
The level 50 sword now has 100 damage, to introduce minD and maxD you should also define "randomness", lets call it random_factor
and set it for all swords to 0.15 (=15%). Now you can get minD and maxD very easily:
minD = (1 - random_factor) * damage
maxD = (1 + random_factor) * damage
Every level 50 sword now has 85 to 115 damage. To improve randomness we will say random factor not same for all swords, but rather within some specific range, lets say from min_rndF = 0.07
to max_rnd_f = 0.24
.
rnd_f = rand(min_rndF, max_rnd_f)
var sword = new Sword(level, rnd_f)
At this point you are at the solution you wanted, level 50 sword can be anywhere between 93-107
and 76-124
swords, all of these having exactly same DPS.
If you want to play with the randomness even further, you might say you dont want to have all the possibilities from above equally likely and for example want the more unbalanced versions(93-107 and 76-124) less likely so that the player would find "average" 85-115 swords more often. In that case you should also choose the distribution.
As I mentioned above, you can also separate the required(displayed) level and the actual level so player can find slightly worse or slightly better swords of same level, that can be achieved in similar manner:
rnd_f = rand(min_rndF, max_rnd_f)
rnd_l = rand(-quality_rnd/*0.1*/, quality_rnd)
var actual_level = (1 + rnd_l) * level
var sword = new Sword(level, actual_level , rnd_f)
This way, level 50 swords can be anywhere between 84-96
(low quality, low randomness), 68-111
(lq, hr), 84-138
(hq, hr) or 103-119
(hq, lr), all equally likely. Or even all not equally likely(if you chose to use non-default distribution).