lundi 26 juin 2017

C# Generation Random Number using r.next(x,y), inside a for loop

Iam trying to generate phi a random number Normal(0,1).However, inside the J loop as I could check (output) r.next(0,10) do not generate a random from o to 10 every J loop. It repeats the same value inside the (FOR J).How can I generate 12 different random (0,10)?and why it does not generate every turn?

// random number generator phi
double phi = 0.0;
double rand = 0;
double rand1 = 0.0;

for (int j = 0; j <= 12; j++)
{
    Random r = new Random();
    rand = (r.Next(0, 10));
    rand1 = rand1 + (Convert.ToDouble(rand) / 10.0);
    Console.WriteLine("j  : {0}, rand {1}, rand1 {2} and 'i' {3} ", j,rand,rand1,i);

}
phi = (rand1 - 6.0);  




Aucun commentaire:

Enregistrer un commentaire