GoGreen PC TuneUp™
Learn More

Insta-Install™
this is how we code sign our software and ssl encrypt our websites from our affiliate partner SSL.com

myBlog

myBlog Home

Back to Blog MTNCOMP


VB.Net and Visual C# random not so random, adjustment to codebase

Published: Thursday, September 19, 2019 written by Drew Jackson
View Count: 25
Keywords: VB.Net, Visual C#, Random, Not So Random



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.
 
 
Imports System.Diagnostics
Imports System.IO
Imports System.Data.SqlClient
Imports System.Threading
Imports System.Net.Http
Imports System.Net
 
         Dim ProcID
        ProcID = Process.GetCurrentProcess().Id
        Debug.Print("ProcID = " & ProcID.ToString)
        ListStatus.Items.Add("ProcID = " & ProcID.ToString)

        Dim r
        Static Generator As System.Random = New System.Random()
        Randomize()
        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 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.

© 2019 myBlog™ v1.1 All rights reserved. We count views as reads, so let's not over think it.