当前位置: 首页>>代码示例>>C#>>正文


C# RandomGenerator.GetRandom方法代码示例

本文整理汇总了C#中RandomGenerator.GetRandom方法的典型用法代码示例。如果您正苦于以下问题:C# RandomGenerator.GetRandom方法的具体用法?C# RandomGenerator.GetRandom怎么用?C# RandomGenerator.GetRandom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RandomGenerator的用法示例。


在下文中一共展示了RandomGenerator.GetRandom方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateRandomData

        public static void GenerateRandomData(string personName)
        {
            var random = new RandomGenerator();

            string rootPath = HttpContext.Current.Server.MapPath("~/Server");

            var attachmentFiles = System.IO.Directory.GetFiles(Path.Combine(rootPath, "attachments"));
            var lipsumParagraphs = System.IO.File.ReadAllLines(Path.Combine(rootPath, "LipsumParagraphs.txt")).Where(l => !string.IsNullOrEmpty(l)).ToList();
            var lipsumTitles = System.IO.File.ReadAllLines(Path.Combine(rootPath, "LipsumTitles.txt")).Where(l => !string.IsNullOrEmpty(l)).ToList();
            var people = new List<AppUser>();

            for (int i = 0; i < 100; i++)
            {
                var person = new AppUser();
                person.Name = random.GetRandom(personNames);
                person.Email = person.Name.ToLowerInvariant() + "@gmail.com";
                person.Id = random.GetRandomNumber(1000000, 9999999);
                people.Add(person);
            }

            var currentUser = people.First(p => p.Name == personName);

            var posts = new List<Post>();
            for (int i = 0; i < random.GetRandomNumber(800, 1200); i++)
            {
                var post = new Post();

                post.Id = random.GetRandomNumber(100000, 999999);
                post.IsFavorite = random.GetRandomDouble() < 0.2;
                post.IsRead = random.GetRandomDouble() < 0.6;
                post.Body = random.GetRandom(lipsumParagraphs);
                post.Subject = random.GetRandom(lipsumTitles);
                post.Sender = random.GetRandom(people);
                post.DateSent = random.GetRandomDate();

                for (int j = 0; j < random.GetRandomNumber(1, 10); j++)
                    post.Recepients.Add(random.GetRandom(people));

                if (random.GetRandomBool())
                {
                    for (int j = 0; j < random.GetRandomNumber(0, 5); j++)
                        post.CC.Add(random.GetRandom(people));
                }

                if (random.GetRandomBool())
                {
                    for (int j = 0; j < random.GetRandomNumber(0, 5); j++)
                        post.BCC.Add(random.GetRandom(people));
                }

                if (random.GetRandomBool())
                {
                    for (int j = 0; j < random.GetRandomNumber(0, 3); j++)
                    {
                        var attachmentFile = new FileInfo(random.GetRandom(attachmentFiles));

                        post.Attachments.Add(new Attachment { Id = Guid.NewGuid().ToString(), Size = random.GetRandomNumber(10000, 10000000), Title = attachmentFile.Name });
                    }
                }

                if (random.GetRandomBool())
                {
                    for (int j = 0; j < random.GetRandomNumber(1, 5); j++)
                    {
                        string randomTag = random.GetRandom(defaultTags);
                        if (!post.Tags.Contains(randomTag))
                            post.Tags.Add(randomTag);
                    }
                }

                posts.Add(post);
            }

            var data = new AppData
            {
                Posts = posts,
                Users = people,
                CurrentUser = currentUser
            };

            SaveDataToDisk(data);
        }
开发者ID:jivkopetiov,项目名称:gmail2,代码行数:82,代码来源:Database.cs


注:本文中的RandomGenerator.GetRandom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。