Results 1 to 28 of 28

Thread: [RESOLVED] Random string

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Resolved [RESOLVED] Random string

    Hi, I've created a small tool to upload binary files to Usenet newsgroups. Every binary file is cut into smaller pieces (about 400kB) and then uploaded to the newsserver. Every piece has its own code (Message-ID) that I put in the header.

    I create Message-ID's of about 45 characters. When creating random strings of about 45 characters there should be billions of combinations, but many of my users get incomplete uploads, because the application creates Message-ID's already created/used by other users.

    Why do so many people create the same strings? Is it because of the Randomize in the function instead of the form_load event?

    This is the code I use to create the Message-ID.
    vb Code:
    1. Private Const CHARS = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    2.  
    3. Private Function RandomString() As String
    4.     Dim i As Long
    5.     Dim tmp As String
    6.  
    7.     Randomize
    8.     For i = 1 To 28
    9.         tmp = tmp & Mid(CHARS, Int(52 * Rnd) + 1, 1)
    10.     Next i
    11.  
    12.     RandomString = tmp & "@application.local"
    13. End Function

    I also tried this function, but the same problem occurs.
    vb Code:
    1. Public Function RandomString() As String
    2.     Dim i       As Long
    3.     Dim btByte  As Byte
    4.  
    5.     Randomize
    6.     For i = 1 To 28
    7.         btByte = Int(Rnd() * 127)
    8.         Select Case btByte
    9.             Case 48 To 57
    10.                 RandomString = RandomString & Chr(btByte)
    11.             Case 65 To 90
    12.                 RandomString = RandomString & Chr(btByte)
    13.             Case 97 To 122
    14.                 RandomString = RandomString & Chr(btByte)
    15.             Case Else
    16.                 i = i - 1
    17.         End Select
    18.     Next i
    19.         RandomString = RandomString & "@application.local"
    20. End Function
    Last edited by Chris001; Jan 27th, 2009 at 03:34 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width