What is the c# equivalent of the following c++:
srand((unsigned)(time(NULL)));
weight=(double)(rand())/(RAND_MAX/2) - 1;
What is the c# equivalent of the following c++:
srand((unsigned)(time(NULL)));
weight=(double)(rand())/(RAND_MAX/2) - 1;
To do random value generation in .NET, you should use the Random class. to seed it with a time value, use: Random rand = new Random((int)DateTime.Now.Ticks);
For further specifics, it's best to check out the docs about the Random class in the MSDN, e.g. which methods are available.
Random rnd = new Random((int)DateTime.Now.Ticks);
return rnd.Next(-1,1);
The paramaterless constructor for Random uses "a time-dependent default seed value" so all you need is:
Random rnd = new Random();
return rnd.Next(-1, 1);