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*

5
  • 4
    I would move System.Environment.TickCount out of the loop. If it ticks over while you are iterating then you will have two items initialized to the same seed. Another option would be to combine the tickcount an i differently (e.g. System.Environment.TickCount<<8 + i) Commented Jun 25, 2009 at 19:03
  • If I understand correctly: do you mean, it could happen, that "System.Environment.TickCount + i" could result the SAME value? Commented Jun 26, 2009 at 13:18
  • EDIT: Of course, no need to have TickCount inside the loop. My bad :). Commented Jun 26, 2009 at 13:19
  • 3
    The default Random() constructor calls Random(Environment.TickCount) anyway Commented Feb 16, 2017 at 16:29
  • @Alsty - Useful observation - if only creae one global Random generator. However, if you call the default Random() constructor twice during the same tick, you will get two Random generators that each generate the exact same sequence of random numbers. Probably not what you want! The above logic (#2) uses seeds TickCount+0, TickCount+1, etc - so the generators are all different. Commented Aug 5, 2020 at 21:57