|
-
Apr 14th, 2006, 03:16 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Compiling byte array
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?
-
Apr 14th, 2006, 03:18 AM
#2
-
Apr 14th, 2006, 03:26 AM
#3
Thread Starter
Hyperactive Member
Re: Compiling byte array
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.
-
Apr 14th, 2006, 05:44 AM
#4
Thread Starter
Hyperactive Member
Re: Compiling byte array
This is what I was tring to do:
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
Compiles two "floped" byte arrays:
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
Last edited by frozen; Apr 14th, 2006 at 05:56 AM.
-
Apr 14th, 2006, 06:05 AM
#5
Re: Compiling byte array
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
-
Apr 14th, 2006, 06:25 AM
#6
Thread Starter
Hyperactive Member
Re: Compiling byte array
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
-
Apr 14th, 2006, 07:27 AM
#7
Re: Compiling byte array
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.
Last edited by leinad31; Apr 14th, 2006 at 07:35 AM.
-
Apr 14th, 2006, 07:44 AM
#8
Thread Starter
Hyperactive Member
-
Apr 14th, 2006, 07:50 AM
#9
Re: Compiling byte array
 Originally Posted by frozen
huh? lol.
Pls be more specific. Which part did you not understand?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|