예제 #1
0
        private void _OkButton_Click(object sender, EventArgs e)
        {
            var x  = ((int)_XNumericUpDown.Value).ToString();
            var y  = ((int)_YNumericUpDown.Value).ToString();
            var sb = new StringBuilder();

            for (int i = y.Length - 1; i >= 0; i--)
            {
                sb.Append(y[i]);
            }
            y = sb.ToString();

            sb.Clear();
            var random = new UtilityRandom();

            sb.Append(random.Next(1, 9));
            sb.Append(_Mode);
            sb.Append(random.Next(1, 9));
            sb.Append(x.Length);
            sb.Append(random.Next(1, 9));
            sb.Append(y.Length);
            sb.Append(random.Next(1, 9));
            sb.Append(x.PadRight(4, random.Next(1, 9).ToString()[0]));
            sb.Append(random.Next(1, 9));
            sb.Append(y.PadLeft(4, random.Next(1, 9).ToString()[0]));

            sb.Append('`');

            Command      = sb.ToString();
            DialogResult = DialogResult.OK;
        }
예제 #2
0
        public static void DoTimeTest()
        {
            UtilityRandom random = new UtilityRandom();
            random.Next();
            IDGenerator geanIdg = new IDGenerator();
            geanIdg.Generate();

            int count = 500 * 10000;

            Stopwatch sw = new Stopwatch();
            Console.WriteLine("Start......");

            //Gean.Data的Id生成器-----------------------
            long geanIdTime;
            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = geanIdg.Generate();
            }
            sw.Stop();
            geanIdTime = sw.ElapsedMilliseconds;

            //随机数字-----------------------
            long randNumTime;
            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = random.Next(1, count).ToString();
            }
            sw.Stop();
            randNumTime = sw.ElapsedMilliseconds;

            //随机4位小写字母-----------------------
            long randTime;
            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = random.GetString(4, UtilityRandom.RandomCharType.Lowercased);
            }
            sw.Stop();
            randTime = sw.ElapsedMilliseconds;

            //数字累计-----------------------
            long gerTime;
            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = (i + i + i).ToString();
            }
            sw.Stop();
            gerTime = sw.ElapsedMilliseconds;

            //IDGenerator生成-----------------------
            long idgTime;
            sw.Reset();
            sw.Start();
            UUIDGenerator idg = new UUIDGenerator();
            for (int i = 0; i < count; i++)
            {
                string id = idg.Generate();
            }
            sw.Stop();
            idgTime = sw.ElapsedMilliseconds;

            //Guid-----------------------
            long guidTime;
            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = Guid.NewGuid().ToString();
            }
            sw.Stop();
            guidTime = sw.ElapsedMilliseconds;

            Console.WriteLine("Gean.Data的Id生成器: " + geanIdTime.ToString() + Sudu(geanIdTime, count));
            Console.WriteLine("随机数字: " + randNumTime.ToString() + Sudu(randNumTime, count));
            Console.WriteLine("随机4位小写字母: " + randTime.ToString() + Sudu(randTime, count));
            Console.WriteLine("数字累计: " + gerTime.ToString() + Sudu(gerTime, count));
            Console.WriteLine("IDGenerator生成: " + idgTime.ToString() + Sudu(idgTime, count));
            Console.WriteLine("Guid: " + guidTime.ToString() + Sudu(guidTime, count));
        }
예제 #3
0
        public static void DoTimeTest()
        {
            UtilityRandom random = new UtilityRandom();

            random.Next();
            IDGenerator geanIdg = new IDGenerator();

            geanIdg.Generate();

            int count = 500 * 10000;

            Stopwatch sw = new Stopwatch();

            Console.WriteLine("Start......");

            //Gean.Data的Id生成器-----------------------
            long geanIdTime;

            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = geanIdg.Generate();
            }
            sw.Stop();
            geanIdTime = sw.ElapsedMilliseconds;

            //随机数字-----------------------
            long randNumTime;

            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = random.Next(1, count).ToString();
            }
            sw.Stop();
            randNumTime = sw.ElapsedMilliseconds;

            //随机4位小写字母-----------------------
            long randTime;

            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = random.GetString(4, UtilityRandom.RandomCharType.Lowercased);
            }
            sw.Stop();
            randTime = sw.ElapsedMilliseconds;

            //数字累计-----------------------
            long gerTime;

            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = (i + i + i).ToString();
            }
            sw.Stop();
            gerTime = sw.ElapsedMilliseconds;

            //IDGenerator生成-----------------------
            long idgTime;

            sw.Reset();
            sw.Start();
            UUIDGenerator idg = new UUIDGenerator();

            for (int i = 0; i < count; i++)
            {
                string id = idg.Generate();
            }
            sw.Stop();
            idgTime = sw.ElapsedMilliseconds;

            //Guid-----------------------
            long guidTime;

            sw.Reset();
            sw.Start();
            for (int i = 0; i < count; i++)
            {
                string id = Guid.NewGuid().ToString();
            }
            sw.Stop();
            guidTime = sw.ElapsedMilliseconds;


            Console.WriteLine("Gean.Data的Id生成器: " + geanIdTime.ToString() + Sudu(geanIdTime, count));
            Console.WriteLine("随机数字: " + randNumTime.ToString() + Sudu(randNumTime, count));
            Console.WriteLine("随机4位小写字母: " + randTime.ToString() + Sudu(randTime, count));
            Console.WriteLine("数字累计: " + gerTime.ToString() + Sudu(gerTime, count));
            Console.WriteLine("IDGenerator生成: " + idgTime.ToString() + Sudu(idgTime, count));
            Console.WriteLine("Guid: " + guidTime.ToString() + Sudu(guidTime, count));
        }
예제 #4
0
        public void Execute()
        {
            string keyDirectory = Path.Combine(basePath, $"{extension}_{gram.GetN()}");

            if (Directory.Exists(keyDirectory) == false)
            {
                Directory.CreateDirectory(keyDirectory);
            }

            StreamWriter writer = File.CreateText($"{keyDirectory}.txt");

            writer.WriteLine("Sequence_Probability,Perplexity,Linearity_JSON_Positions,Leniency");

            ICompiledGram compiled       = gram.Compile();
            ICompiledGram simpleCompiled = simplifiedGram?.Compile();

            for (int i = 0; i < numSimulations; ++i)
            {
                UtilityRandom.SetSeed(new DateTime().Millisecond);

                Tuple <List <string>, List <string> > tuple;

                if (gram as NGram == null)
                {
                    tuple = GetColumnsBestGuess(compiled, simpleCompiled);
                }
                else
                {
                    tuple = GetColumnsSemiGuaranteed(compiled, simpleCompiled);
                }

                List <string> columns    = tuple.Item1;
                List <string> simplified = tuple.Item2;

                string[]   columnsArray  = columns.ToArray();
                List <int> positions     = LevelAnalyzer.Positions(columnsArray);
                JsonArray  jsonPositions = new JsonArray();
                foreach (int pos in positions)
                {
                    jsonPositions.Add(pos);
                }

                double sequenceProbability = compiled.SequenceProbability(columnsArray);
                writer.Write($"{sequenceProbability},");
                if (sequenceProbability == 0)
                {
                    writer.Write($"0,");
                }
                else
                {
                    writer.Write($"{1d/sequenceProbability},");
                }

                writer.Write($"{jsonPositions},");
                writer.Write($"{LevelAnalyzer.Leniency(simplified.ToArray())}\n");

                StreamWriter levelWriter = File.CreateText(Path.Combine(keyDirectory, $"{i}.txt"));
                levelWriter.Write(string.Join("\n", columnsArray));
                levelWriter.Flush();
                levelWriter.Close();

                if (i % 200 == 0)
                {
                    writer.Flush();
                }
            }

            writer.Flush();
            writer.Close();
        }
예제 #5
0
 public static int RandomIndex <T>(this List <T> list)
 {
     return(UtilityRandom.RandInt(0, list.Count));
 }