Reputation: 1393
I cannot convert those I see in VB.Net I wanted to create something like a "Word Factory" So I need to produce a random letter. I managed to get a random number using this
Dim x, first, last
first = 65
last = 90
x = Int((last - Min + 1) * Rnd + Min)
How about random letters from the alphabet? in VB6. Thanks.
Upvotes: 1
Views: 1292
Reputation: 881403
You can turn an integer code point into a character with the Chr()
function, and go back the other way with Asc()
.
That means you can get a random letter with code such as:
Dim mych As String
mych = Chr(Asc("A") + 26 * Rnd)
Upvotes: 2
Reputation: 43
Could you use a similar technique to the random number, but have the random number as the index of an array of characters?
On unrelated note you may want to pay attention to the distribution of the random letters, weighting some of the more common letters so they occur more frequently.
Upvotes: 1