mercredi 24 avril 2019

Why my created random function just work for one time?

Thank you for helping me!

There is a piece of random function I found on the Internet, called GetRandom. I put it like below

 public static double GetRandom(double[] array)
  {    
       Random ran = new Random();
    int n = ran.Next(array.Length);
    return array[n];
  }

 private void Window_Activated(object sender, System.EventArgs e)
    {   


        c1 = c-GetRandom(arr);
        c2 = c-GetRandom(arr);
......

    }

arr is a double arry containing a a few doubles. c1,c2,c3 .... are all double. Howeve, it seems that every GetRandom(arr) in the last few lines return the same result.How come? The n in GetRandom can't be refreshed after each use?




Aucun commentaire:

Enregistrer un commentaire