yousra yousef yousra yousef - 1 year ago 72
ASP.NET (C#) Question

why the random numbers in the debug change but in the run time fixed?

I'm working now on a project with c# and windows form , I have to generate random floating numbers between 0,1 using random rand= new random() ;
float rnd=(float)rand.nextdouble();
, my problem is the randoms are correct only in the debug section when it display on gridview but in the run section the first random number is fixed all the time on the gridview doesn't change . is there any solution ??

Answer Source

I assume you create a new Random instance on every call. Keep using one instance and call rand.NextDouble(); on that instance.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download