0

I'm trying to randomize a cell value for each cell. I want to keep the letters "tyot" at the front of the word, then randomize the 7 letters after it, which I did with this formula:

=CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90))& CHAR(RANDBETWEEN(65,90))&RANDBETWEEN(10,99) 

and after joining both cells with a formula like =A1&""&B1 I got the results that i want which it looks like this tyotXKWAE73. Now the next step is what i cant figure it out, which is randomizing the last six letter "tXKWAE73" and leaving "tyot"always on the front. Any ideas on how to do this last step?

dwirony
  • 5,487
  • 3
  • 21
  • 43
user3326780
  • 29
  • 1
  • 4

1 Answers1

0

Enter the following functions in a standard module:

Public Function Shuffle(s As String) As String
    Dim ary(1 To 7) As String, ndex(1 To 7)
    For i = 1 To 7
        ary(i) = Mid(s, i, 1)
        ndex(i) = i
    Next i
    Call Shuffle2(ndex)
    Shuffle = ""
    For i = 1 To 7
        Shuffle = Shuffle & ary(ndex(i))
    Next i
End Function

Public Sub Shuffle2(InOut() As Variant)
    Dim i As Long, J As Long
    Dim tempF As Double, Temp As Variant

    Hi = UBound(InOut)
    Low = LBound(InOut)
    ReDim Helper(Low To Hi) As Double
    Randomize

    For i = Low To Hi
        Helper(i) = Rnd
    Next i

    J = (Hi - Low + 1) \ 2
    Do While J > 0
        For i = Low To Hi - J
          If Helper(i) > Helper(i + J) Then
            tempF = Helper(i)
            Helper(i) = Helper(i + J)
            Helper(i + J) = tempF
            Temp = InOut(i)
            InOut(i) = InOut(i + J)
            InOut(i + J) = Temp
          End If
        Next i
        For i = Hi - J To Low Step -1
          If Helper(i) > Helper(i + J) Then
            tempF = Helper(i)
            Helper(i) = Helper(i + J)
            Helper(i + J) = tempF
            Temp = InOut(i)
            InOut(i) = InOut(i + J)
            InOut(i + J) = Temp
          End If
        Next i
        J = J \ 2
    Loop
End Sub

Then in B1 enter:

=CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90)) & CHAR(RANDBETWEEN(65,90))& CHAR(RANDBETWEEN(65,90))&RANDBETWEEN(10,99)

In B2 enter:

="tyot" & shuffle(B$1)

and copy downward:

enter image description here

Each entry in column B is a "randomization" of B1 with a fixed prefix.

Gary's Student
  • 95,722
  • 10
  • 59
  • 99