/// <summary> /// handles values larger than int32 max /// returns random within range /// </summary> private static string HandleLargeValue(Spn spn, Random rand) { double output = 0; double multiplier = (double)(spn.Highvalue / (decimal)(Int32.MaxValue)); var num = (int)multiplier; var dec = multiplier - num; for (int i = 0; i < num; i++) { output += rand.Next(1, Int32.MaxValue); } var remain = (int)(dec * Int32.MaxValue); if (remain > 0) { output += rand.Next(1, remain); } if (spn.Factor > 0) { var deciml = new Random().Next(0, spn.Factor * 10); double decPart = deciml / (spn.Factor * 10.0); output += decPart; } return(output.ToString(CultureInfo.InvariantCulture)); }
/// <summary> /// handles possible negative values /// returns random within range /// </summary> private static string HandleNegativeValue(Spn spn, Random rand) { double output = 0; string s = string.Empty; var absLowValue = (double)(Math.Abs(spn.Lowvalue)); var chanceofnegative = absLowValue + (double)spn.Highvalue; chanceofnegative = absLowValue / chanceofnegative; int chanceoutof100 = (int)chanceofnegative * 100; //let fate decide if we should be negative //if so: if (rand.Next(0, 100) < chanceoutof100) { //produce negative output value if (absLowValue > Int32.MaxValue) { return("-" + HandleLargeValue(spn, rand)); } return("-" + HandleSmallValue(spn, rand)); } //otherwise: if (spn.Highvalue <= Int32.MaxValue) { return(HandleSmallValue(spn, rand)); } return(HandleLargeValue(spn, rand)); }
/// <summary> /// handles small values < int32 max /// returns random within range /// </summary> private static string HandleSmallValue(Spn spn, Random rand) { double output = 0; int lowval = 0; int highval = (int)(spn.Highvalue); output = rand.Next(lowval, highval); return(output.ToString()); }
public SpnLookup(string columnHeaders, List <String> lines) { Header = columnHeaders; Lookup = new Dictionary <int, Spn>(); foreach (var line in lines) { var spn = new Spn(line); Lookup.Add(spn.SpnNumber, spn); SpnCount++; } }
public SpnLookup(string columnHeaders, List<String> lines) { Header = columnHeaders; Lookup = new Dictionary<int, Spn>(); foreach (var line in lines) { var spn = new Spn(line); Lookup.Add(spn.SpnNumber, spn); SpnCount++; } }
/// <summary> /// returns valid random value for spn /// </summary> private string GetValue(Spn spn) { var rand = new Random(); double output = 0; if (spn.Highvalue <= Int32.MaxValue) { return(HandleSmallValue(spn, rand)); } //determine how likely we are to generate a negative number, and then determine if we should, then do it if (spn.Lowvalue < 0) { return(HandleNegativeValue(spn, rand)); } return(HandleLargeValue(spn, rand)); }
/// <summary> /// handles values larger than int32 max /// returns random within range /// </summary> private static string HandleLargeValue(Spn spn, Random rand) { double output = 0; double multiplier = (double) (spn.Highvalue/(decimal) (Int32.MaxValue)); var num = (int) multiplier; var dec = multiplier - num; for (int i = 0; i < num; i++) { output += rand.Next(1, Int32.MaxValue); } var remain = (int)(dec *Int32.MaxValue); if (remain > 0) { output += rand.Next(1, remain); } if (spn.Factor > 0) { var deciml = new Random().Next(0, spn.Factor*10); double decPart = deciml/(spn.Factor*10.0); output += decPart; } return output.ToString(CultureInfo.InvariantCulture); }
/// <summary> /// returns valid random value for spn /// </summary> private string GetValue(Spn spn) { var rand = new Random(); double output = 0; if (spn.Highvalue <= Int32.MaxValue) { return HandleSmallValue(spn, rand); } //determine how likely we are to generate a negative number, and then determine if we should, then do it if (spn.Lowvalue < 0) { return HandleNegativeValue(spn, rand); } return HandleLargeValue(spn, rand); }
/// <summary> /// handles small values < int32 max /// returns random within range /// </summary> private static string HandleSmallValue(Spn spn, Random rand) { double output = 0; int lowval = 0; int highval = (int) (spn.Highvalue); output = rand.Next(lowval, highval); return output.ToString(); }
/// <summary> /// handles possible negative values /// returns random within range /// </summary> private static string HandleNegativeValue(Spn spn, Random rand) { double output = 0; string s = string.Empty; var absLowValue = (double) (Math.Abs(spn.Lowvalue)); var chanceofnegative = absLowValue + (double) spn.Highvalue; chanceofnegative = absLowValue/chanceofnegative; int chanceoutof100 = (int) chanceofnegative*100; //let fate decide if we should be negative //if so: if (rand.Next(0, 100) < chanceoutof100) { //produce negative output value if (absLowValue > Int32.MaxValue) { return "-" + HandleLargeValue(spn, rand); } return "-" + HandleSmallValue(spn, rand); } //otherwise: if (spn.Highvalue <= Int32.MaxValue) { return HandleSmallValue(spn, rand); } return HandleLargeValue(spn, rand); }