Hi Lee,

This solution occurred to me but I rejected it because it would
involve a number of changes to the OP's existing code such as :

Making the Random object static would necessitate that the "foo"
method be static too. Then it can no more be virtual because a method
cannot be static as well as virtual void.

A better way is to create a Random object in the calling code (the
void Main()) and pass it to the Factory class. However, I rejected
that method too in the interest of keeping the code as similar to the
existing implementation.

On Jun 22, 6:59 pm, "Lee Gunn" <[email protected]> wrote:
> Hi,
>
> The problem is arising because the "Random" class is being instantiated 
> everytime the foo() method is called. And, as mentioned below, becuase the 
> code is running so fast the default seed used (current datetime) is the same. 
> To get round this, simply use a ** static ** "Random" object. There will be 
> only one instance of it and you can quite happily keep calling Next() to 
> generate a new unique random number...
>
> Lee
>
> --http://www.secretorange.co.uk
>
>
>

Reply via email to