public static bool ferma(LongArithmetic x) { //Random rnd = new Random(); LaggedFibRandom rnd = new LaggedFibRandom((int)(DateTime.UtcNow.ToBinary() % 1000000000)); for (int j = 2; j < 100; j++) { if (x % j == 0 && x != j) { return(false); } } for (int i = 0; i < 20; i++) { LongArithmetic a = (rnd.Next() % (x - 2)) + 2; if (gcd(a, x) != 1) { return(false); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Проверка {0} на простоту. Тест {1}:", x.ToString(), i + 1); Console.ForegroundColor = ConsoleColor.White; if (mypows(a, x - 1, x) != 1) { return(false); } } return(true); }
public static LongArithmetic Random() { //Random rnd = new Random(); LaggedFibRandom rnd = new LaggedFibRandom((int)(DateTime.UtcNow.ToBinary() % 1000000000)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < Times; i++) { sb.Append(rnd.Next() % 10000); } LongArithmetic res = LongArithmetic.Parse(sb.ToString()); return(res); }