- Microsoft Excel
- Microsoft Office

In the attached workbook, a UDF was coded to generate a numerical value, based upon a character string. Part 2 would actually be the reverse. If one has a numerical value, then what random 16 character hexadecimal string would = a numeric value. This doesn't have to be directly related to the values generated within the UDF, in fact, it shouldn't be. The reason for wanting a random 16 character hexadecimal string is that any number of 16 character strings could equal a particular value.

For example:

If there is numerical value that equals 65, then that value would translate into any number of 16 digit Hexadecimal characters (0-F). The 16 digit string 80201BA30A910532 equals the number 65. But, as can be seen, any number of characters could have been used to satisfy the 65 value...that's why a random 16 digit string that equals a particular number is desired.

Cook09

getvalues-from-Number.xlsm

For example:

If there is numerical value that equals 65, then that value would translate into any number of 16 digit Hexadecimal characters (0-F). The 16 digit string 80201BA30A910532 equals the number 65. But, as can be seen, any number of characters could have been used to satisfy the 65 value...that's why a random 16 digit string that equals a particular number is desired.

Cook09

getvalues-from-Number.xlsm

Function getstring(rng As Range)

Dim i As Integer

Dim n As Integer

Dim res As Integer

Application.Volatile

res = rng.Value

For i = 1 To 15

n = Int(Rnd() * WorksheetFunction.Min(16, res))

getstring = getstring & IIf(n < 10, n, Chr(n + 55))

res = res - n

Next i

n = res

getstring = getstring & IIf(n < 10, n, Chr(n + 55))

End Function

Function getstring(rng As Range, strlen As Integer)

Dim i As Integer

Dim n As Integer

Dim res As Integer

Application.Volatile

res = rng.Value

If strlen * 15 < res Then

getstring = "#Overflow"

Exit Function

End If

For i = 1 To strlen

avl = res - 15 * (strlen - i)

If avl < 1 Then

n = Int(Rnd() * WorksheetFunction.Min(strl

Else

n = Rnd() * (15 - avl) + avl

End If

getstring = getstring & IIf(n < 10, n, Chr(n + 55))

res = res - n

Next i

End Function

## Premium Content

You need an Expert Office subscription to comment.Start Free Trial