/// <summary> /// Initialize information on the daily trends for food. /// </summary> public void InitializeDailyTrends() { // Initialize the string that the trend string will be set to. string trendString = ""; // Get a list of all different types of dishes. List <Dish> dishList = this.gameSceneManager.GetAcquiredRecipes().ToList(); // Initialize likelihoods adding up to 1 indicating how popular the dish will be. List <float> foodPopularities = NumberRandomizer.GenerateNFloatsWhoSumToM(dishList.Count, 1f).ToList(); // Append each dish and its popularity onto the trend string. dishPopularityMapping = new Dictionary <Dish, float>(); for (int index = 0; index < dishList.Count; index++) { Dish d = dishList[index]; float dishPopularity = foodPopularities[index]; trendString += $"{d.ToTitleCaseSpacedString()}: {dishPopularity * 100:F2}%"; // Append a newline to the end of the string if we still have more recipe popularities to render. if (index < dishList.Count - 1) { trendString += "\n"; } // Be sure to keep track of how popular each dish is in a Dictionary. dishPopularityMapping[d] = dishPopularity; } // Finally, set the trend string. this.trendingFoodText.text = trendString; }
/// <summary> /// Generate and print a number of floats that sum to the number 1. /// </summary> private static void GenerateLogFloatsWhoSumToM() { IEnumerable <float> generateNFloatsWhoSumToM = NumberRandomizer.GenerateNFloatsWhoSumToM(5, 1f); string convertToString = generateNFloatsWhoSumToM.AsString(); Debug.Log(convertToString); Debug.Log(generateNFloatsWhoSumToM.Sum()); }