ผมต้องการ สุ่มตัวเลข เพื่อนำมาสร้างเป็น สมการ 2 ตัวแปร แล้วก็จะหาค่า x y ครับ 
โค้ด
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้       public static async Task<TermExpression> GenerateExpressionTwo()
       {
           // รูปแบบสมการ 2 ตัวแปร
           string p1 = "";
           string p2 = "";
           int a, b, c, d, e, f, x = 0, y = 0;
           // สุ่มตัวเลขสำหรับตัวแปร a, b, c, d, e, f
           var tasks = new[]
           {
       RandomNumber.GenerateNonZeroRandomAsync(-20, 20), // สำหรับ a
       RandomNumber.GenerateNonZeroRandomAsync(-20, 20), // สำหรับ b
       RandomNumber.GenerateNonZeroRandomAsync(-20, 20), // สำหรับ c
       RandomNumber.GenerateNonZeroRandomAsync(-20, 20), // สำหรับ d
       RandomNumber.GenerateNonZeroRandomAsync(-20, 20), // สำหรับ e
       RandomNumber.GenerateNonZeroRandomAsync(-20, 20)  // สำหรับ f
   };
           var results = await Task.WhenAll(tasks);
           a = results[0];
           b = results[1];
           c = results[2];
           d = results[3];
           e = results[4];
           f = results[5];
           // รูปแบบสมการที่สุ่ม
           int equationType = RandomNumber.GenerateRandomNumber(1, 10); // 1 - 9 รูปแบบ
           switch (equationType)
           {
               case 1:
                   // รูปแบบ: Ax + By = C และ Dx + Ey = F
                   p1 = $"{a}x + {b}y = {c}";
                   p2 = $"{d}x + {e}y = {f}";
                   // คำนวณค่า x และ y โดยการใช้เทคนิคการคูณ
                   x = (c * e - f * b) / (a * e - b * d);
                   y = (a * f - d * c) / (a * e - b * d);
                   break;
               case 2:
                   // รูปแบบ: Ax + By = C และ Dx = F + Ey
                   p1 = $"{a}x + {b}y = {c}";
                   p2 = $"{d}x = {f} + {e}y";
                   // คำนวณค่า x และ y
                   x = (c * e - f * b) / (a * e - b * d);
                   y = (a * f - d * c) / (a * e - b * d);
                   break;
               case 3:
                   // รูปแบบ: Ax + By = C และ Dx + C = Ey
                   p1 = $"{a}x + {b}y = {c}";
                   p2 = $"{d}x + {f} = {e}y";
                   // คำนวณค่า x และ y
                   x = (c * e - f * b) / (a * e - b * d);
                   y = (a * f - d * c) / (a * e - b * d);
                   break;
               case 4:
                   // รูปแบบ: Ax = C + By และ Dx + Ey = F
                   p1 = $"{a}x = {c} + {b}y";
                   p2 = $"{d}x + {e}y = {f}";
                   // คำนวณค่า x และ y
                   x = (c * e - f * b) / (a * e - b * d);
                   y = (a * f - d * c) / (a * e - b * d);
                   break;
               case 5:
                   // รูปแบบ: Ax = C + By และ Dx = F + Ey
                   p1 = $"{a}x = {c} + {b}y";
                   p2 = $"{d}x = {f} + {e}y";
                   // คำนวณค่า x และ y
                   x = (c * e - f * b) / (a * e - b * d);
                   y = (a * f - d * c) / (a * e - b * d);
                   break;
               case 6:
                   // รูปแบบ: Ax = C + By และ Dx + C = Ey
                   p1 = $"{a}x = {c} + {b}y";
                   p2 = $"{d}x + {f} = {e}y";
                   // คำนวณค่า x และ y
                   x = (c * e - f * b) / (a * e - b * d);
                   y = (a * f - d * c) / (a * e - b * d);
                   break;
               case 7:
                   // รูปแบบ: Ax + C = By และ Dx + Ey = F
                   p1 = $"{a}x + {c} = {b}y";
                   p2 = $"{d}x + {e}y = {f}";
                   // คำนวณค่า x และ y
                   x = (c * e - f * b) / (a * e - b * d);
                   y = (a * f - d * c) / (a * e - b * d);
                   break;
               case 8:
                   // รูปแบบ: Ax + C = By และ Dx = F + Ey
                   p1 = $"{a}x + {c} = {b}y";
                   p2 = $"{d}x = {f} + {e}y";
                   // คำนวณค่า x และ y
                   x = (c * e - f * b) / (a * e - b * d);
                   y = (a * f - d * c) / (a * e - b * d);
                   break;
               case 9:
                   // รูปแบบ: Ax + C = By และ Dx + C = Ey
                   p1 = $"{a}x + {c} = {b}y";
                   p2 = $"{d}x + {f} = {e}y";
                   // คำนวณค่า x และ y
                   x = (c * e - f * b) / (a * e - b * d);
                   y = (a * f - d * c) / (a * e - b * d);
                   break;
           }
           // ปรับปรุงสมการให้ดูดี
           string s = $"{p1} and {p2}";
           s = s.Replace("--", "+").Replace("-+", "-")
                 .Replace("- -", "+").Replace("+ -", "-").Replace("- +", "-")
                 .Replace("+ -", "+");
           return new TermExpression(s, $"x = {x}, y = {y}");
       }
แต่พบปัญหาคือ ค่า x y ที่ได้ส่วนมีแต่ 0 กับ 1 ซะส่วนใหญ่
Solution:-17x = 7 -12y and -19x = -10 -4y 
x = 0, y = -1
Solution:8x + 14 = -20y and -11x -14y = 19 
x = 0, y = 0
Solution:2x = 12 -6y and -12x = 11 -10y 
x = 0, y = -1
Solution:5x + 9y = 1 and -10x + 13y = -19 
x = 1, y = 0
Solution:-1x -20 = -20y and -5x = 1 + 15y 
x = 2, y = 0
Solution:1x + 13y = -7 and -15x -1y = -2 
x = 0, y = 0
Solution:2x = -6 + 1y and -18x -16 = 5y 
x = 0, y = -5
Solution:-6x -7 = -9y and -3x -4 = -20y 
x = 1, y = 0
Solution:-19x -3y = -16 and 1x + 11y = -13 
x = 1, y = -1
Solution:-11x = 18 -10y and 19x = 9 -12y 
x = 0, y = -1
Solution:4x + 4 = -20y and -18x = -4 -9y 
x = 0, y = 0
Solution:8x -13 = 9y and 1x -6 = 9y 
x = -1, y = 0
Solution:-3x + 13 = 16y and -6x = 11 -11y 
x = -2, y = 0
Solution:4x = 13 -4y and 6x -20 = -5y 
x = -36, y = -39
Solution:-4x + 15 = 15y and 16x = -12 -7y 
x = 0, y = 0
Solution:-8x = 6 -15y and -16x + 3 = -6y 
x = 0, y = 0
Solution:-17x = -16 + 16y and -6x + 5y = 7 
x = -17, y = -19
Solution:-19x + 4 = 7y and -18x = 7 + 16y 
x = 0, y = 0
Solution:8x + 8y = 4 and 16x -16y = 10 
x = 0, y = 0
Solution:-12x = 9 -19y and -8x + 12y = -7 
x = 0, y = 0
ผมควรสุ่มยังไงดีครับ หรือ เปลี่ยน สลับตรงไหน ยังไง ค่าถึงจะสวยขึ้น																															
 
						
รบกวนขอวิธีสุ่มตัวเลขหน่อยครับ
โค้ด
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้
แต่พบปัญหาคือ ค่า x y ที่ได้ส่วนมีแต่ 0 กับ 1 ซะส่วนใหญ่
Solution:-17x = 7 -12y and -19x = -10 -4y
x = 0, y = -1
Solution:8x + 14 = -20y and -11x -14y = 19
x = 0, y = 0
Solution:2x = 12 -6y and -12x = 11 -10y
x = 0, y = -1
Solution:5x + 9y = 1 and -10x + 13y = -19
x = 1, y = 0
Solution:-1x -20 = -20y and -5x = 1 + 15y
x = 2, y = 0
Solution:1x + 13y = -7 and -15x -1y = -2
x = 0, y = 0
Solution:2x = -6 + 1y and -18x -16 = 5y
x = 0, y = -5
Solution:-6x -7 = -9y and -3x -4 = -20y
x = 1, y = 0
Solution:-19x -3y = -16 and 1x + 11y = -13
x = 1, y = -1
Solution:-11x = 18 -10y and 19x = 9 -12y
x = 0, y = -1
Solution:4x + 4 = -20y and -18x = -4 -9y
x = 0, y = 0
Solution:8x -13 = 9y and 1x -6 = 9y
x = -1, y = 0
Solution:-3x + 13 = 16y and -6x = 11 -11y
x = -2, y = 0
Solution:4x = 13 -4y and 6x -20 = -5y
x = -36, y = -39
Solution:-4x + 15 = 15y and 16x = -12 -7y
x = 0, y = 0
Solution:-8x = 6 -15y and -16x + 3 = -6y
x = 0, y = 0
Solution:-17x = -16 + 16y and -6x + 5y = 7
x = -17, y = -19
Solution:-19x + 4 = 7y and -18x = 7 + 16y
x = 0, y = 0
Solution:8x + 8y = 4 and 16x -16y = 10
x = 0, y = 0
Solution:-12x = 9 -19y and -8x + 12y = -7
x = 0, y = 0
ผมควรสุ่มยังไงดีครับ หรือ เปลี่ยน สลับตรงไหน ยังไง ค่าถึงจะสวยขึ้น