alexpanoiu

Random SIgnature Generator

Dec 7th, 2018 (edited)
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Compare Binary
  2. Option Explicit
  3.  
  4. Function RandSignature() As String
  5.  
  6.   Dim NumSyllables As Variant
  7.   Dim i As Long
  8.  
  9.   Select Case RandChoice(4)
  10.   Case 0: NumSyllables = Array(2, 2, 4)
  11.   Case 1: NumSyllables = Array(2, 3, 3)
  12.   Case 2: NumSyllables = Array(3, 1, 4)
  13.   Case 3: NumSyllables = Array(3, 2, 3)
  14.   End Select
  15.  
  16.   For i = LBound(NumSyllables) To UBound(NumSyllables)
  17.     RandSignature = RandSignature _
  18.       & IIf(i > LBound(NumSyllables), " ", "") & RandName(NumSyllables(i))
  19.   Next i
  20.  
  21. End Function
  22.  
  23. Function RandName(ByVal NumSyllables As Long) As String
  24.  
  25.   Dim i As Long
  26.   Dim s As String
  27.   Dim DiphthongUsed As Boolean '= False
  28.  
  29.   For i = 1 To NumSyllables
  30.     s = ""
  31.     If i > 1 Or RandChance(4 / 5) Then
  32.       Do
  33.         s = Mid$("bcdfghjklmnpqrsStTvwxyzZ", 1 + RandChoice(24), 1)
  34.       Loop Until _
  35.         InStr("iy mh mm my nh nn ny uw Ww Yy", Right$(RandName, 1) & s) = 0
  36.       If Len(RandName) > 0 And InStr("aeiou", Right$(RandName, 1)) > 0 _
  37.         And InStr("chjqSTwxyZ", s) = 0 And RandChance(1 / 3) _
  38.       Then
  39.         s = s & s
  40.       End If
  41.     End If
  42.     If InStr("bfgkpsSvz", s) > 0 And RandChance(1 / 3) Then
  43.       s = s & Mid$("lr", 1 + RandChoice(2), 1)
  44.     ElseIf InStr("dtT", s) > 0 And RandChance(1 / 6) Then
  45.       s = s & "r"
  46.     End If
  47.     If Right$(s, 1) = "y" Then
  48.       s = s & Mid$("aeou", 1 + RandChoice(4), 1)
  49.     ElseIf Right$(s, 1) = "q" Or Right$(s, 1) = "w" Then
  50.       s = s & Mid$("aeio", 1 + RandChoice(4), 1)
  51.     Else
  52.       s = s & Mid$("aeiou", 1 + RandChoice(5), 1)
  53.     End If
  54.     If DiphthongUsed Then
  55.       If RandChance(1 / 4) Then s = s & Mid$("mn", 1 + RandChoice(2), 1)
  56.     Else
  57.       If InStr("aeo", Right$(s, 1)) > 0 And RandChance(1 / 3) Then
  58.         s = s & Mid$("mnWY", 1 + RandChoice(4), 1)
  59.       ElseIf InStr("i", Right$(s, 1)) > 0 And RandChance(1 / 3) Then
  60.         s = s & Mid$("mn", 1 + RandChoice(2), 1)
  61.       ElseIf InStr("u", Right$(s, 1)) > 0 And RandChance(1 / 3) Then
  62.         s = s & Mid$("mnY", 1 + RandChoice(3), 1)
  63.       End If
  64.       DiphthongUsed = InStr("WY", Right$(s, 1)) > 0
  65.     End If
  66.     RandName = RandName & s
  67.   Next i
  68.  
  69.   If Len(RandName) < 2 Or InStr("iu", Right$(RandName, 1)) > 0 _
  70.     Or (InStr("aeo", Right$(RandName, 1)) > 0 _
  71.     And RandChance(IIf(Right$(RandName, 1) = "e", 2 / 3, 1 / 3))) _
  72.   Then
  73.     RandName = RandName & Mid$("dfgKlmnprsStTvxz", 1 + RandChoice(16), 1)
  74.   End If
  75.  
  76.   If InStr("n", Right$(RandName, 1)) > 0 And RandChance(1 / 2) Then
  77.     RandName = RandName & Mid$("dkts", 1 + RandChoice(5), 1)
  78.   ElseIf InStr("lr", Right$(RandName, 1)) > 0 And RandChance(1 / 2) Then
  79.     RandName = RandName & Mid$("kmnpts", 1 + RandChoice(5), 1)
  80.   ElseIf InStr("f", Right$(RandName, 1)) > 0 And RandChance(1 / 2) Then
  81.     RandName = RandName & Mid$("kts", 1 + RandChoice(3), 1)
  82.   ElseIf InStr("s", Right$(RandName, 1)) > 0 And RandChance(1 / 2) Then
  83.     RandName = RandName & Mid$("kt", 1 + RandChoice(2), 1)
  84.   ElseIf InStr("km", Right$(RandName, 1)) > 0 And RandChance(1 / 2) Then
  85.     RandName = RandName & Mid$("ts", 1 + RandChoice(2), 1)
  86.   ElseIf InStr("p", Right$(RandName, 1)) > 0 And RandChance(1 / 2) Then
  87.     RandName = RandName & Mid$("s", 1 + RandChoice(1), 1)
  88.   End If
  89.  
  90.   RandName = Replace$(RandName, "c", "ch")
  91.   RandName = Replace$(RandName, "K", "ck")
  92.   RandName = Replace$(RandName, "q", "qu")
  93.   RandName = Replace$(RandName, "S", "sh")
  94.   RandName = Replace$(RandName, "T", "th")
  95.   RandName = Replace$(RandName, "Z", "zh")
  96.   RandName = Replace$(RandName, "W", "u")
  97.   RandName = Replace$(RandName, "Y", "i")
  98.   RandName = Replace$(RandName, "kk", "ck")
  99.   RandName = Replace$(RandName, "nb", "mb")
  100.   RandName = Replace$(RandName, "np", "mp")
  101.  
  102.   If Right$(RandName, 1) = "u" Then
  103.     RandName = Left$(RandName, Len(RandName) - 1) & "w"
  104.   ElseIf Right$(RandName, 1) = "i" Then
  105.     RandName = Left$(RandName, Len(RandName) - 1) & "y"
  106.   End If
  107.  
  108.   RandName = UCase$(Left$(RandName, 1)) & Mid$(RandName, 2)
  109.  
  110. End Function
  111.  
  112. Function RandChance(ByVal Chance As Double) As Boolean
  113.  
  114.   RandChance = Rand < Chance
  115.  
  116. End Function
  117.  
  118. Function RandChoice(ByVal NumChoices As Long) As Long
  119.  
  120.   RandChoice = Int(IIf(NumChoices > 1, NumChoices, 1) * Rand)
  121.  
  122. End Function
  123.  
  124.   #Const UseShuffling = False
  125. ' #Const UseShuffling = True
  126.  
  127. Function Rand(Optional ByVal Seed = -1) As Double
  128.  
  129. ' Stephen K. Park and Keith W. Miller, "Random number generators: good ones are
  130. ' hard to find", in Communications of the ACM, volume 31 (1988), number 10,
  131. ' pp. 1192-1201. The method of computing the next number in the sequence
  132. ' x = (a x) mod m is due to Linus Schrage, first described in his paper "A more
  133. ' portable Fortran random number generator", in ACM Transactions on Mathematical
  134. ' Software, vol.5 (1979), pp.132-138.
  135.  
  136.   Const Modulus As Long = 2147483647
  137.   Const Multiplier As Long = 69621
  138.   Const Quotient As Long = Modulus \ Multiplier '= 30845
  139.  Const Remainder As Long = Modulus Mod Multiplier '= 23902
  140.  
  141.   Static RandValue As Long '= 0
  142.  
  143.   #If UseShuffling Then
  144. ' The shuffling technique is described in William H. Press et al., Numerical
  145. ' Recipes in Fortran 77 - The Art of Scientific Computing, Second Edition,
  146. ' Volume 1 of Fortran Numerical Recipes, Cambridge University Press, 1992,
  147. ' ISBN 0-521-43064-X, in section 7.1 "Uniform Deviates", pp.267-277.
  148.  
  149.   Const ShuffleSize As Long = 32
  150.   Const ShuffleDiv As Long = 1 + (Modulus - 1) \ ShuffleSize
  151.   Static ShuffleArray(1 To ShuffleSize) As Long
  152.   Static OutputValue As Long
  153.   #End If
  154.  
  155.   Dim i As Long
  156.  
  157.   If RandValue <= 0 Or Seed >= 0 Then
  158.     Seed = Seed Mod Modulus
  159.     If Seed <= 0 Then Seed = _
  160.       (1 + (((CLng(Date) Mod 65536) * 25173 + 13849) Mod 65536) \ 338) _
  161.       * (1 + Int(CDbl(Timer) * 128#))
  162.     RandValue = Seed
  163.     #If UseShuffling Then
  164.     OutputValue = 0
  165.     #End If
  166.     For i = 1 To 100
  167.       Rand
  168.       #If UseShuffling Then
  169.       If i > ShuffleSize Then
  170.         If OutputValue <= 0 Then OutputValue = RandValue
  171.       ElseIf i > 0 Then
  172.         ShuffleArray(i) = RandValue
  173.       End If
  174.       #End If
  175.     Next i
  176.   End If
  177.  
  178.   RandValue = _
  179.     Multiplier * (RandValue Mod Quotient) - Remainder * (RandValue \ Quotient)
  180.   If RandValue < 0 Then RandValue = RandValue + Modulus
  181.  
  182.   #If UseShuffling Then
  183.   If OutputValue > 0 Then
  184.     i = 1 + OutputValue \ ShuffleDiv
  185.     OutputValue = ShuffleArray(i)
  186.     ShuffleArray(i) = RandValue
  187.   End If
  188.   Rand = OutputValue / Modulus
  189.   #Else
  190.   Rand = RandValue / Modulus
  191.   #End If
  192.  
  193. End Function
Advertisement