6
I set a random number to fill a fictitious table and did so:
foreach (var usuario in LstUsuarios)
{
htmlUsuarios.AppendLine("<tr>");
htmlUsuarios.AppendLine("<td>" + usuario.Nome + "</td>");
htmlUsuarios.AppendLine("<td><strong>" + usuario.NomePerfil + "</strong></td>");
htmlUsuarios.AppendLine("<td>" + usuario.UnidadeGerencial.Txt_Sigla_UG + "</td>");
for (var i = 1; i <= num_periodos; i++)
{
rnd = new Random();
random = rnd.Next(1, 99);
htmlUsuarios.AppendLine("<td> " + random + "</td>");
}
htmlUsuarios.AppendLine("<td>100</td>");
htmlUsuarios.AppendLine("</tr>");
}
But the application is always showing the same number.
The curious thing is that when I debug in the visual studio it actually generates different numbers.
What is outside the red line is the part that I debugged in VS, I was checking with the breakpoints and the numbers were changing. But when I pressed keep on the VS it would generate the same number as the ones inside the red line.
I don’t understand why. Any idea?
I would only add one detail to say that this happens because as an instance of
Random
is created at each iteration, theseed
will be the same (without passing aseed
theRandom
uses theEnviroment.TickCount
) and hence have repeated numbers. Behavior was not observed duringDebug
because the code will run more slowly which allows to haveseeds
different.– Omni
@Omni that very thing !!!
– user6026
And you have an idea why when I’m debugging it generates different numbers?
– Joao Paulo
Juxtaposition because of Enviroment.Tickcount will have another value in the debug, and in each F11 for, for example, it will change the millisecond calculation
– user6026
@Joaopaulo "The behavior was not observed during Debug because the code will be executed more slowly which allows to have different Eds." This slowness may come from the user debugging step by step or from the simple overhead caused by Debugger.
– Omni