VB.Net and Visual C# random not so random, adjustment to codebase
by Andy Flagg, Publication Date: Thursday, September 19, 2019
View Count: 224, Keywords: VB.Net, Visual C#, Random, Not So Random, Hashtags: #VB.Net #VisualC# #Random #NotSoRandom
we just used the process ID to help with the randomization by
adding to the random value found plus the process ID integer to get away
from the collisions we found in the random number generator.
our coding for a huge, and I mean huge internet based program function had a random generator function that did not end up being so random. if you have a multi-threaded, multi-processor, multi-connected application and utility working on a 100+ million record set and need random search and find and access results, do something like the following.
ProcID = Process.GetCurrentProcess().Id
Debug.Print("ProcID = " & ProcID.ToString)
ListStatus.Items.Add("ProcID = " & ProcID.ToString)
Static Generator As System.Random = New System.Random()
r = Generator.Next(1, maxDBrecords)
r = r + ProcID
we cut away some of the code for while and looping but you get the idea.
the maxDBrecords was 118 million + and growing, so you can imagine our dilemma with collisions.
more to come...
if you found this article helpful, consider contributing $10, 20 an Andrew Jackson or so..to the author. more authors coming soon
FYI we use paypal or patreon, patreon has 3x the transaction fees, so we don't, not yet.
© 2021 myBlog™ v1.1 All rights reserved. We count views as reads, so let's not over think it.