我正在使用以下代码:
var a = (new Random()).Next(2);
这是在一个小循环内。每次它将 a 的值设置为零。有人可以就我做错了什么给我一些建议吗?
更新
感谢您提供的建议,但我仍然只看到一个数字:-( 这是我添加建议后的代码:
var r1 = new Random();
var r2 = new Random();
foreach (var entry in this.ChangeTracker.Entries()
.Where(
e => e.Entity is IAuditableTable &&
(e.State == EntityState.Added) ||
(e.State == EntityState.Modified)))
{
IAuditableTable e = (IAuditableTable)entry.Entity;
if (entry.State == EntityState.Added)
{
e.CreatedBy = r1.Next(2);
e.CreatedDate = DateTime.Today.AddDays(-1 * r2.Next(30));
}
e.ModifiedBy = r1.Next(2);
e.ModifiedDate = DateTime.Today.AddDays(-1 * r2.Next(30));
}
CreatedBy 和 ModifiedBy 总是得到 0 :-(