Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using System;
- using System.Threading;
- namespace serialize
- {
- class Generator
- {
- public (int, int, int, int) GetMod(int diff)
- {
- int mod1 = 1;// +-
- int mod2 = 1;// +-
- int mod3 = 1;// */
- int mod4 = 1;// */
- if (diff == 0)
- {
- mod1 = 101;// +-
- mod2 = 101;// +-
- mod3 = 11;// */
- mod4 = 11;// */
- }
- if (diff == 1)
- {
- mod1 = 11;
- mod2 = 11;
- mod3 = 10;
- mod4 = 10;
- }
- return (mod1, mod2, mod3, mod4);
- }
- public static char GetSign()
- {
- Random rnd = new Random();
- int tmp = rnd.Next() % 4;
- char result = '.';
- switch (tmp)
- {
- case (0):
- result = '+';
- break;
- case (1):
- result = '-';
- break;
- case (2):
- result = '*';
- break;
- case (3):
- result = '/';
- break;
- default:
- break;
- }
- return result;
- }
- public (int, int) GetPair(int mod1, int mod2)
- {
- Random rnd = new Random();
- int res1, res2;
- res1 = (rnd.Next() % mod1) + 1;
- res2 = (rnd.Next() % mod2) + 1;
- return (res1, res2);
- }
- public (string, char, string, int) Build(char Sign, int diff)
- // first sign second result
- {
- (string, char, string, int) result;
- var MOD = GetMod(diff);
- if (Sign == '+')
- {
- (int, int) Expression = GetPair(MOD.Item1, MOD.Item2);
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 + Expression.Item2;
- }
- else
- if (Sign == '-')
- {
- (int, int) Expression = GetPair(MOD.Item1, MOD.Item2);
- if (Expression.Item1 < Expression.Item2)
- {
- int a = Expression.Item1;
- Expression.Item1 = Expression.Item2;
- Expression.Item2 = a;
- }
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 - Expression.Item2;
- }
- else
- if (Sign == '/')
- {
- (int, int) Expression = GetPair(MOD.Item3, MOD.Item4);
- Expression.Item1 = Expression.Item2 * Expression.Item1;
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 / Expression.Item2;
- }
- else
- {
- (int, int) Expression = GetPair(MOD.Item3, MOD.Item4);
- result.Item1 = Expression.Item1.ToString();
- result.Item2 = Sign;
- result.Item3 = Expression.Item2.ToString();
- result.Item4 = Expression.Item1 * Expression.Item2;
- }
- return result;
- }
- static void Main(string[] args)
- {
- int diff = 0;
- //for (int i = 0; i < 25; ++i)
- {
- Generator abs = new Generator();
- //for (int j = 0; j < 6500000; j++) ;
- var a = abs.Build(GetSign(), diff);
- Thread.Sleep(1);
- var b = abs.Build(GetSign(), diff);
- // Console.WriteLine(a);
- // Console.WriteLine(b);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement