Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Random default constructor system clock resolution?

Tags:

c#

.net

random

I have several processes in which I use System.Random's default constructor to generate random numbers. I read about it on MSDN but it dosn't say the specific system clock resolution it uses, for example does System.Random get the system clock seed in ms or seconds? Is it safe to use the default constructor across several process to get random values between them?

Cheers

like image 403
KaiserJohaan Avatar asked Feb 18 '23 14:02

KaiserJohaan


1 Answers

it's uses the Environment.TickCount you can check it in Reflector. But the point is to get an unique seed, so you can use an arithmetic operation on this value with the ProcessID . like:

Random(Environment.TickCount + System.Diagnostics.Process.GetCurrentProcess().Id);

etc.

like image 146
Jacob Avatar answered Feb 21 '23 02:02

Jacob