Private Sub RndBitsVerify() ' "Random Bits Verify" ' Print a frequency count of the bits within values generated by the Visual Basic Rnd function. 'See also: ' RndBytesVerify ' RndVerify Dim avarBitCnt() As Variant ReDim avarBitCnt(1 To 32) Const NTries = 100000 Const NReport = 10000 Randomize Dim lngTry As Long For lngTry = 1 To NTries If lngTry Mod NReport = 0& Then Debug.Print Format$(lngTry, "#,##0") Dim sngRnd As Single Dim strRnd As String sngRnd = Rnd strRnd = MakeSingleFast(sngRnd) Dim intCurByt As Integer For intCurByt = 1 To Len(sngRnd) Dim intCurVal As Integer intCurVal = ASC(Mid$(strRnd, intCurByt, 1)) Dim intCurBit As Integer For intCurBit = 1 To 8 If intCurVal And (2 ^ intCurBit - 1) Then Dim intAbsBit As Integer intAbsBit = (intCurByt - 1) * 8 + intCurBit avarBitCnt(intAbsBit) = avarBitCnt(intAbsBit) + 1& End If Next intCurBit Next intCurByt Next lngTry Debug.Print IllustrateVariantVector(avarBitCnt) End Sub
Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.