I want to compile a byte array (0 To 255) of numbers from 0-255, something like
b(0) = 12
b(1) = 18
b(2) = 24
b(3) = 8
b(4) = 45
b(5) = 23
b(6) = 67
b(7) = 1
...
But I can't seem to do it, ideas?
Printable View
I want to compile a byte array (0 To 255) of numbers from 0-255, something like
b(0) = 12
b(1) = 18
b(2) = 24
b(3) = 8
b(4) = 45
b(5) = 23
b(6) = 67
b(7) = 1
...
But I can't seem to do it, ideas?
whats the problem?
I suck at explaining :P
I need a loop that will fill a byte array full of numbers from 0 to 255 in a random order.
This is what I was tring to do:
Compiles two "floped" byte arrays:VB Code:
Option Explicit Private Sub CompileByteArrays() Dim sNumbers As String Dim iLoop As Integer Dim iRand As Integer Dim b1(0 To 255) As Byte Dim b2(0 To 255) As Byte For iLoop = 0 To 5 sNumbers = sNumbers & ";" & iLoop Next iLoop sNumbers = Mid$(sNumbers, 2) For iLoop = 0 To 5 iRand = Int(NumTok(sNumbers, 59) * Rnd) + 1 b1(iLoop) = GetTok(sNumbers, iRand, 59) b2(GetTok(sNumbers, iRand, 59)) = iLoop sNumbers = RemTok(sNumbers, iRand, 59) Next iLoop Text1.Text = "" Text2.Text = "" For iLoop = 0 To 5 Text1.Text = Text1.Text & "b(" & iLoop & ") = " & b1(iLoop) & vbCrLf Text2.Text = Text2.Text & "b(" & iLoop & ") = " & b2(iLoop) & vbCrLf Next End Sub
Code:b(0) = 3
b(1) = 4
b(2) = 0
b(3) = 2
b(4) = 1
b(5) = 5
Code:b(0) = 2
b(1) = 4
b(2) = 3
b(3) = 0
b(4) = 1
b(5) = 5
VB Code:
Private Sub Command1_Click() Dim b1(0 To 255) As Byte Dim b2(0 To 255) As Byte Dim i As Integer Randomize For i = 0 To 255 b1(i) = Rnd * 255 b2(i) = Rnd * 255 Debug.Print "b1(" & i & ")= " & b1(i) & " b2(" & i & ")= " & b2(i) Next i End Sub
The number can only be in the byte array once.
What I was trying to do was make a program to compile a random byte array to remap the ASCII values of characters in a string. The sub I wrote compiles bEncodeMap() and bDecodeMap() for the following functions.
VB Code:
Public Function bEncode(ByRef s As String) As String Dim i As Integer bEncode = "" For i = 1 To Len(s) bEncode = bEncode & Chr(bEncodeMap(Asc(Mid$(s, i, 1)))) Next i End Function Public Function bDecode(ByRef s As String) As String Dim i As Integer bDecode = "" For i = 1 To Len(s) bDecode = bDecode & Chr(bDecodeMap(Asc(Mid$(s, i, 1)))) Next i End Function
Instead of adding them from index 0 to 255 in random order, try creating a sorted array first then call a randomizer procedure which will swap the values contained in 2 randomly selected indices (from 0 to 255, the 2 generated indices must not be the same). Swap positions of array member pairs n number of times... make it a large num, you would end up doing around 255 factorial comparisons if you approached it as inserting random numbers from position 0 to 255 anyway.
huh? lol.
Pls be more specific. Which part did you not understand?Quote:
Originally Posted by frozen