I have a section of code that is being used to determine if a certain event should happen. The code looks like this.
If (Date.Now.Ticks Mod 100) < 4 Then Return True Else Return False End If
The idea here is that this event should happen 4 time out of 100, or 4%. However, in production, the actually percentages range from 10% to 60%. The application is being hosted on two load balanced Win2k3 servers.
Any suggestion would be helpful.
Keith
The reason you’re getting that behavior is you’re not asking for 4% of the time that you be given a True value, you’re asking that any time the number of Ticks modulo 100 is less than 4.
Given a uniform random number generator, as in System.Random:
With Random.NextDouble you will have an equal probability that any number from 0.0 to 1.0 will be selected. Hence I can ask for True 4% of the time by returning true whenever the random double is less than 0.04.