示例#1
0
        public static string RandomWord(int n)
        {
            var lookup  = new char[2];
            var builder = new StringBuilder(n);

            while (builder.Length < n)
            {
                if (builder.Length < 2)
                {
                    builder.Append(RndUtil.Choice(Bigrams));
                    continue;
                }

                lookup[0] = builder[builder.Length - 2];
                lookup[1] = builder[builder.Length - 1];

                var bigram     = new string(lookup);
                var candidates = builder.Length == n - 1 ? Trigrams.GetOrDefault(bigram)?.Item2 : Trigrams.GetOrDefault(bigram)?.Item1;

                if (candidates?.Length > 0)
                {
                    builder.Append(RndUtil.Choice(candidates));
                }
                else
                {
                    builder.Length = Math.Max(0, builder.Length - 3);
                }
            }
            return(builder.ToString().ToLower());
        }
示例#2
0
        public static string RandomText(int n)
        {
            var builder = new StringBuilder(n);

            while (builder.Length < n)
            {
                builder.Append(RandomWord(RndUtil.GetInt(2, 10)));
                builder.Append(' ');
            }
            builder.Length = n;
            builder[0]     = char.ToUpper(builder[0]);
            return(builder.ToString());
        }
示例#3
0
        public static Bitmap RndBmp(int width, int height)
        {
            var files = Directory.GetFiles(DirPath);

            var file1 = (Bitmap)Image.FromFile(RndUtil.Choice(files));
            var file2 = (Bitmap)Image.FromFile(RndUtil.Choice(files));

            var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (var dbmp = new DirectBitmap(bmp, 0, 0, width, height))
                using (var dbmp1 = GetRandomWindow(file1, width, height))
                    using (var dbmp2 = GetRandomWindow(file2, width, height))
                    {
                        for (int x = 0; x < width; x++)
                        {
                            for (int y = 0; y < height; y++)
                            {
                                dbmp.FastSetPixel(x, y, dbmp1.FastGetPixel(x, y).Blend(dbmp2.FastGetPixel(x, y)));
                            }
                        }
                    }

            return(bmp);
        }