I am fetching "Key" and "Value" from the DB and for each I want to insert a random string in value field.
Problem is that every "Value" field gets the same random string (same random value). How can they get random string, separately, each one different?
foreach (var fields in formFields)
{
FieldValues.Add(new FieldValues
{
Key = item.Key,
Value = RandomString(10,true)
});
}
public string RandomString(int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
}
if (lowerCase)
return builder.ToString().ToLower();
return builder.ToString();
}