OK, if you're trying to update an existing record, what do you think
db.Users.Add
does? Your code is specifically creating a new user and saving it to the table!
You have to retrieve the existing user object(s) from the database, assign the random numbers to them, then save the changes back to the database.
Random rand = new Random();
var users = db.Users;
foreach (var user in users)
{
user.Codigo = rand.Next(1000, 10000);
}
db.SaveChanges();