Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

srand((unsigned)(time(NULL))); (rand())/(RAND_MAX/2) - 1 C# equivalent

What is the c# equivalent of the following c++:

srand((unsigned)(time(NULL)));
weight=(double)(rand())/(RAND_MAX/2) - 1;

1 Answers

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);
like image 102
ICR Avatar answered Nov 30 '25 10:11

ICR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!