Pao wrote:
> My code works in this way:
> I declared a static array in a class (public static int[] GVetRandom =
> new int[3]
> that in a for cycle I fill with random numbers.
> The array gets cleared (clear method) and refilled at each turn of
> cycle.
>
> On my developing pc, the same sequence of random numbers was repeated
> from on turn of cycle to the other; I put some Application.DoEvents()
> and all gone well.
>
> But in the customer's pc, the array are generated exactly the same
> yet, it gives 2 or 3 duplicates
> for example:
> 1st turn in teh for: the array is 10-56-33
> 2nd turn in teh for: the array is 34-22-54
> 3rd turn in teh for: the array is 34-22-54
> 4th turn in teh for: the array is 34-22-54
> 5th turn in teh for: the array is 65-31-24
>
> what could it be???
What are you using as the seed for your random numbers? A guess is that
possibl you are using a date or time that isn't precise enough. A random
number generator with the same seed will produce the same "random" numbers.
Take a look at the following examples:
// this will produce the same results several times through the loop
for (int h = 0; h < 100; h++)
{
DateTime now = DateTime.Now;
int seed = now.Second * 1000 + now.Millisecond;
Random random = new Random(seed);
int[] rand = new int[3];
for (int i = 0; i < rand.Length; i++)
{
rand[i] = random.Next(0, 100);
}
Console.WriteLine("{0}-{1}-{2}", rand[0], rand[1], rand[2]);
}
// this will be much more random than the first example
DateTime now = DateTime.Now;
int seed = now.Second * 1000 + now.Millisecond;
Random random = new Random(seed);
for (int h = 0; h < 100; h++)
{
int[] rand = new int[3];
for (int i = 0; i < rand.Length; i++)
{
rand[i] = random.Next(0, 100);
}
Console.WriteLine("{0}-{1}-{2}", rand[0], rand[1], rand[2]);
}
If that's not it, if you post a sample code that reproduces the problem, no
doubt someone can point out the cause.
--
Tom Porterfield