I’m making a random loot generator prototype, and I’m trying to use randomised stats to make unique weapons. Each stat uses a fixed number as a ‘base’, and I randomly select two of those stats and change them around a bit. I have it working for just 2 numbers (one up, one down):
float[] baseStats = new float[7]; //base for all of the loot to go on.
float[] lootStats = new float[7]; //numbers generated by randomisation. Most stay the same.
//I define the specific numbers elsewhere, it's not important for this
int buffStat; //decide what stats to buff and nerf
int debuffStat;
void GenerateLoot()
{
buffStat = Random.Range(0, lootStats.Length);
debuffStat = Random.Range(0, lootStats.Length);
//pick the two stats to generate.
if (buffStat == debuffStat) //in the event that it picked two of the same, reroll the debuff number
{
while(buffStat == debuffStat)
{
debuffStat = Random.Range(0, lootStats.Length);
}
}
lootStats[buffStat] = baseStats[buffStat] * Random.Range(110, 130)/100; //buff
lootStats[debuffStat] = baseStats[debuffStat] * Random.Range(70, 90)/100; //nerf
}
This works well enough for just 2 stats, but I’m having trouble getting 3 or more selected without repeats. I could certainly brute force it at every new number (if equal to this, or this or this, reroll) but I’m certain there’s a much simpler way to get this.