0

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 ??

  • 1
    Don't keep recreating a `new Random()` - it uses a timestamp which only changes every ~20ms for its seed. Create one `Random` and reuse it. – Matthew Watson Oct 20 '16 at 09:06

1 Answers1

0

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

Andre
  • 1,228
  • 11
  • 24