mood
mood
CC#
Created by mood on 7/12/2023 in #help
❔ Seeing the same Random() seed on separate program startups and different times
Hi all, I'm seeing a non-isolated issue pop up related to the Random() class and its association with the system Environment.TickCount variable. I'm working on .NET Framework 4.5 and while I'm aware that there are issues with Random() and Framework, I'm struggling to see the reason behind my problem. On program startup a Random object is declared and initialized with the default parameterless constructor. Days, weeks, or even months later, I will generate the same seed on a different program startup (I know this because I print the tick count). This obviously causes collisions with the numbers generated. It's happened enough times that it's causing issues for me, and I feel as if it should be virtually impossible to have this repeatability. Is there something that I'm fundamentally missing that increases the likelihood of this problem? private Random mRand = null; mRand = new Random(); To generate the numbers, I'm calling mRand.Next(65536); Any help is appreciated, thanks!
19 replies