本文整理汇总了C#中RandomGenerator.GetRandomNumber方法的典型用法代码示例。如果您正苦于以下问题:C# RandomGenerator.GetRandomNumber方法的具体用法?C# RandomGenerator.GetRandomNumber怎么用?C# RandomGenerator.GetRandomNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RandomGenerator
的用法示例。
在下文中一共展示了RandomGenerator.GetRandomNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePost
public static void CreatePost(string title, string body, string to)
{
var random = new RandomGenerator();
var post = new Post();
var data = GetDataFromDisk();
post.Id = random.GetRandomNumber(100000, 999999);
post.Body = body;
post.Subject = title;
post.Recepients.Add(new AppUser { Email = to });
post.DateSent = DateTime.Now;
data.Posts.Add(post);
SaveDataToDisk(data);
}
示例2: 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);
}