public static StrAttDistribution LoadDistributionFile(string filename) { List <string> names = new List <string>(); List <double> lowLimit = new List <double>(); List <double> hiLimit = new List <double>(); var assembly = Assembly.GetExecutingAssembly(); string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith(filename)); using (Stream stream = assembly.GetManifestResourceStream(resourceName)) using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); names.Add(values[0]); lowLimit.Add(double.Parse(values[1])); hiLimit.Add(double.Parse(values[2])); } } StrAttDistribution dist = new StrAttDistribution(names, lowLimit, hiLimit); return(dist); }
private static string ResultFromDistribution(StrAttDistribution d, bool uniform = false) { if (uniform) //Disregard underlying populatity of names, pretend its uniform { int nIdx = MathUtils.RangeUniform(0, d.Names.Count); return(d.Names[nIdx]); } double bound = d.HiLimit[^ 1];
public static string GetRandomFirstName(bool uniform = false) { if (fnames.Equals(default(StrAttDistribution))) { fnames = LoadDistributionFile("FName.txt"); } return(ResultFromDistribution(fnames, uniform)); }