YouTube-style ID numbers
YouTube-style ID numbers are typically generated as unique, short, and alphanumeric strings that are URL-safe. Here's an ASP function that generates such IDs:
How It Works:
Character Set: The chars variable contains a set of URL-safe characters (a-z, A-Z, 0-9, -, _).
Random Length: The ID is set to a fixed length of 11 characters, mimicking YouTube's style.
Random Generation: For each character in the ID, a random index is generated to pick a character from the chars string.
Output: The function concatenates the selected characters to form a unique string.
Rate YouTube-style ID numbers
(0(0 Vote))
<%
Function GenerateYouTubeID()
Dim chars, idLength, id, i, randomIndex
' Define the characters allowed in the ID
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
idLength = 11 ' Standard YouTube ID length is 11 characters
id = ""
' Generate a random ID
Randomize ' Initialize the random number generator
For i = 1 To idLength
randomIndex = Int((Len(chars) * Rnd) + 1) ' Random index from 1 to length of chars
id = id & Mid(chars, randomIndex, 1) ' Append the random character
Next
GenerateYouTubeID = id
End Function
' Example usage
Dim newYouTubeID
newYouTubeID = GenerateYouTubeID()
Response.Write("Generated YouTube ID: " & newYouTubeID)
%>
YouTube-style ID numbers Comments
No comments yet — be the first to post one!
Post a Comment