I am using the following code:
var a = (new Random()).Next(2);
This is inside of a small loop. Each time it sets the value of a to zero. Can someone give me some advice on what I am doing wrong?
Update
Thanks for the advice given but I still see just the one number:-( Here is my code after I added the suggestions:
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));
}
Always the CreatedBy and ModifiedBy get a 0 :-(