I need to associate each instance of a class with a random int, but I can’t use DI or anything other than the said class.
If I use SomeClass
and that I have many instances created one after the other, they will have the same SomeInt
, but I do not want that.
I cannot use any DI, or factory.
How to achieve this ?
<code>class SomeClass
{
Random _r = new();
public int SomeInt {get;}
SomeClass()
{
SomeInt = _r.Next(int.MaxValue);
}
}
</code>
<code>class SomeClass
{
Random _r = new();
public int SomeInt {get;}
SomeClass()
{
SomeInt = _r.Next(int.MaxValue);
}
}
</code>
class SomeClass
{
Random _r = new();
public int SomeInt {get;}
SomeClass()
{
SomeInt = _r.Next(int.MaxValue);
}
}