public List <StringVariant> Variate(double defaultWeight) { List <StringVariant> resultList = new List <StringVariant>(); // С помощью нашего класса - счетчика счетчиков списков, "собираем" нужную строку. while (true) { String resultString = ""; double resultWeight = 1.00; for (int i = 0; i < listListOfStringVariants.Count; i++) { resultString += listListOfStringVariants[i][listCounter.counters[i][0]].getValue(); double curWeightNotNull = defaultWeight; double?curWeight = listListOfStringVariants[i][listCounter.counters[i][0]].getWeight(); if (curWeight != null) { curWeightNotNull = curWeight.Value; } resultWeight *= curWeightNotNull; } resultWeight = Math.Round(resultWeight, 2); StringVariant sv = new StringVariant(resultString, resultWeight); resultList.Add(sv); if (!listCounter.iterate()) { break; } } return(resultList); }
public static StringVariant generateRandomInstance() { // фабрика для объекта со случайными полями String randomValue; double?randomWeight; Random x = new Random(); int randomNum = x.Next(1, VALUE_LENGTH_MAX); StringRandomizer stringRandomizer = new StringRandomizer(); randomValue = stringRandomizer.getRandomString(randomNum); randomWeight = generateRandomWeight(WEIGHT_MAX + 0.10); // увеличиваем наш максимальный вес, чтобы получить null StringVariant randomInstance; randomInstance = new StringVariant(randomValue, randomWeight); return(randomInstance); }
private List <List <StringVariant> > generateListListStringVariant(int upperListSize) { List <List <StringVariant> > resultList = new List <List <StringVariant> >(); for (int i = 0; i < upperListSize; i++) { Random x = new Random(); int randomNum = x.Next(1, VAR_MAX); List <StringVariant> innerList = new List <StringVariant>(); for (int j = 0; j < randomNum; j++) { StringVariant stringVariant = StringVariant.generateRandomInstance(); innerList.Add(stringVariant); } resultList.Add(innerList); } return(resultList); }