Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 3
    for what is DateTime.Now.Millisecond? Commented Nov 27, 2017 at 12:33
  • 2
    You need to put something for it to start with...... the Random object simply does lots of math on the value you give, and does so in a way that each call of Next() on the same Random object will result in a value quite random to the previous call. To make the result more random across different Random objects , you start with a different number -- here, the DateTime.Now.Millisecond. If you put a constant, rather than a changing value, you would get the same results from .Next(). Commented Dec 28, 2017 at 0:05
  • 26
    Random is already seeded with a system value, and Millisecond is only a number between 0 and 999. If this pair of lines were always together in code, there would only be 1000 possible values of rnd.Next due to the seed being reset each time. Same seed in, same random number out. I'd leave the manual seed out. Commented Sep 13, 2018 at 14:32
  • 1
    @JohnMcDonald, you are correct. Just to be precise, it is initialized with Environment.TickCount. Commented Apr 18, 2020 at 10:41
  • Thanks, it worked! I made it like this: var rnd = new Random(DateTime.Now.Millisecond + i); in the loop where "i" is incremental in the loop. Commented Dec 7, 2021 at 2:16