Changes

no edit summary
Line 32: Line 32:     
I'm trying to calculate expected profits for mushroom logs, so I looked at the game code, and in particular the random number used to generate the quantity of mushrooms. The wiki says it's "a random number between 0.5 and 1.5". The game code uses "Game1.random.Next(1, 3) * (nearbyTrees.Count / 2)". Looking up the definition, the documentation of Next(int minValue, int maxValue) gives us: "A 32-bit signed integer greater than or equal to minValue and less than maxValue; that is, the range of return values includes minValue but not maxValue." So it's exclusive and generates one of two integers: either 1 or 2. Meaning the random number would be 0.5 or 1, with a 50% chance of either one happening. Could someone double check me? This is the first time I'm reading C# and I also don't understand why "Game1.random.Next(1, 3) * (nearbyTrees.Count / 2)" would always be an integer. [[User:Lc-hobby|Lc-hobby]] ([[User talk:Lc-hobby|talk]]) 13:03, 16 April 2024 (UTC)
 
I'm trying to calculate expected profits for mushroom logs, so I looked at the game code, and in particular the random number used to generate the quantity of mushrooms. The wiki says it's "a random number between 0.5 and 1.5". The game code uses "Game1.random.Next(1, 3) * (nearbyTrees.Count / 2)". Looking up the definition, the documentation of Next(int minValue, int maxValue) gives us: "A 32-bit signed integer greater than or equal to minValue and less than maxValue; that is, the range of return values includes minValue but not maxValue." So it's exclusive and generates one of two integers: either 1 or 2. Meaning the random number would be 0.5 or 1, with a 50% chance of either one happening. Could someone double check me? This is the first time I'm reading C# and I also don't understand why "Game1.random.Next(1, 3) * (nearbyTrees.Count / 2)" would always be an integer. [[User:Lc-hobby|Lc-hobby]] ([[User talk:Lc-hobby|talk]]) 13:03, 16 April 2024 (UTC)
 +
 +
I think I calculated the expected number of mushrooms spawned per number of trees in the 7x7 square. random.Next maxvalue is exclusive, so random nr is either 1 or 2. n_trees/2 is rounded towards 0 (integer division). So n_trees/2 is [0,0,1,1,2,2,3,3,4,4,5] for 0 throuh 10 n_trees. With random.Next(1,3) equal to 1 and 2 respectively, we have [1,1,1,1,2,2,3,3,4,4,5] and [1,1,2,2,4,4,5,5,5,5,5] mushrooms produced. Hence the expected value of the number of mushrooms for 0 to 10 trees is [1,1,1,1,2,2,3,3,4,4,5] + [1,1,2,2,4,4,5,5,5,5,5] / 2 = [1,1,1.5,1.5,3,3,4,4,4.5,4.5,5]. So interestingly, due to the rounding down towards 0 in the integer division, 3, 5, 7, and 9 trees do not add any benefit to the number of mushrooms when compared to 2, 4, 6, and 8 trees in the 7x7 square. [[User:Lc-hobby|Lc-hobby]] ([[User talk:Lc-hobby|talk]]) 12:53, 19 April 2024 (UTC)
2

edits