mardi 21 avril 2015

Simplifying redundant variable assignment

I don't like this code, it is overcomplicated and impractical, so I'm looking to simplify it.

I want it to change a var by a random amount, and I need to put at least 150 variables into this code.

//Variable list

public double price1 = 100;
public double price2 = 100;
public double price3 = 100;

public void DaysEnd(){ //Simplified version of inefficient code

var = price1;
HVariation();
price1 = newvar;

var = price2;
HVariation();
price2 = newvar;

var = price2;
MVariation();
price2 = newvar;

var = price3;
LVariation();
price3 = newvar;
}

public void Hvariation(){
    newvar = var + (var * (Random.NextDouble(0 - 0.5, 0.5)));
}
public void Mvariation(){
    newvar = var + (var * (Random.NextDouble(0 - 0.25, 0.25)));
}
public void Lvariation(){
    newvar = var + (var * (Random.NextDouble(0 - 0.1, 0.5)));
}




Aucun commentaire:

Enregistrer un commentaire