<% Dim intDigitTally(9) Dim intHugeDataset(9) 'PARAMETERS intCountSize = Request.QueryString("CountSize") intCountStopChance = Request.QueryString("Chance") 'DEFAULTS intHugeDataset(1) = 30.1 intHugeDataset(2) = 17.6 intHugeDataset(3) = 12.5 intHugeDataset(4) = 9.7 intHugeDataset(5) = 7.9 intHugeDataset(6) = 6.7 intHugeDataset(7) = 5.8 intHugeDataset(8) = 5.1 intHugeDataset(9) = 4.6 If intCountSize = "" Then intCountSize = 1000 Else intCountSize = CLng(intCountSize) End If If intCountSize > 10000 Then intCountSize = 10000 If intCountStopChance = "" Then intCountStopChance = 100 Else intCountStopChance = CInt(intCountStopChance) End If If intCountStopChance > 10000 Then intCountStopChance = 10000 %>

Benford's Law

The count of a thing can end sooner than later, eh?

">
Number of counts:
Chance of each count stopping: 1 in
<% If intCountSize = 10000 And intCountStopChance = 1000 Then %>

Count size 10,000 and stop chance of 1-in-1,000 is a little slow. Running...

<% End If If intCountSize = 10000 And intCountStopChance = 10000 Then %>

Count size 10,000 and stop chance of 1-in-10,000 is slow. Running...

<% End If Response.Flush Randomize For intX = 1 to intCountSize intCount = 1 'A 1-in-x chance that the count will stop. Do While Int(Rnd * intCountStopChance) <> 0 intCount = intCount + 1 Loop 'Increment the tally of the leading digit. intDigitTally(CInt(Left(intCount, 1))) = intDigitTally(CInt(Left(intCount, 1))) + 1 Next intTotalDigitTally = 0 For intX = 1 to 9 intTotalDigitTally = intTotalDigitTally + intDigitTally(intX) Next %> <% For intX = 1 to 9 %> <% Next %>
Leading
Digit
Leading
Digit
Tally
Leading
Digit
Percent
Documented
Huge Dataset
Percent*
<%=intX%> <%=intDigitTally(intX)%> <%=(100 * intDigitTally(intX) / intTotalDigitTally)%>% <%=intHugeDataset(intX)%>%

Classic ASP vbscript source code

*Wikipedia