Last active
November 6, 2017 00:45
-
-
Save mc3k/b15db2c717c4bf154fd17d9f23a1a08e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function StaticRandom(Input1 As String, Optional Rand_Input As Double = 0) As Variant | |
' Create a pseudo random number which doesn't change for a given input | |
' Martin Childs, 2016-07-05 | |
' v001 | |
' | |
Prime = 9973 | |
'Checksum | |
checksum = Len(Input1) | |
For i = 1 To Len(Input1) | |
Input3 = Mid(Input1, i, 1) | |
checksum = checksum + (Asc(Input3) + Rand_Input) * i | |
Next i | |
StaticRandom = Prime / checksum | |
'Hash | |
For i = 1 To Len(Input1) | |
If IsNumeric(Mid(Input1, i, 1)) Then | |
Input4 = Mid(Input1, i, 1) | |
Else | |
Input4 = Asc(Mid(Input1, i, 1)) | |
End If | |
Input2 = Input2 + (Input4 + Rand_Input) * i | |
' Enable for more 'random' | |
' If (i < Len(Input1)) = True Then | |
' Input2 = Input2 + (IfNumber(Mid(Input1, i + 1, 1), Asc(Mid(Input1, i + 1, 1))) + Rand_Input) * i | |
' End If | |
StaticRandom = StaticRandom + Prime / Asc(Input2) | |
Next i | |
StaticRandom = StaticRandom - Int(StaticRandom) | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment