![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2005
Posts: 62
Rep Power: 4
![]() |
displaying random characters
ok here's something confusing the heck outta me. i'm making a random password generator of sorts, giving the user the option of numbers, lowercase letters, uppercase letters, or any combination thereof. there's more to the program than this obviously, but this is the relevant code i have set up to complete this task:
Function Random(Lowerbound As Long, Upperbound As Long)
Random = Int(Rnd * Upperbound) + Lowerbound
End Function
...
Let route = Random(1, 3)
If route = 1 And chkuppercase.Value = 1 Then ' generate an uppercase letter
For r = 1 To txtLen.Text
Let m = Random(65, 90)
output = output & Chr(m)
Next r
End If
If route = 2 And chklowercase.Value = 1 Then ' generate a lowercase letter
For r = 1 To txtLen.Text
Let n = Random(97, 122)
output = output & Chr(n)
Next r
End If
If route = 3 And chknumber.Value = 1 Then ' generate a number
For r = 1 To txtLen.Text
output = output & Random(0, 9)
Next r
End Ifi don't know if anyone can understand what exactly i've done with the code or the role of all the variables, but allow me to tell you what happens as a result of execution: 1. a random number within the respective ASCII range (uppercase 65-90, lowercase 97-122) is stored in variable m or n. m corresponds to uppercase letters, n with lowercase letters. 2. a chr(m) and chr(n) statement (is supposed to) append the corresponding character or number to string 'output.' 3. string 'output' ends up consisting of a bunch of gibberish hash marks and non-alphanumeric characters. sometimes i do get actual numbers or text, but not often. so, any ideas as to why i'm not getting actual alpha/numeric output all the time? all i could find in my own research was somebody using a non-system font having this problem, but i tried terminal, times new roman, lucida console, ms sans serif; every default font i could think of but it didn't make a difference. i suspect there may be a problem with my randomize function...? thanks |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Your random-number function is a little dodgy - it should do this:
Random = Int(Rnd * (Upperbound - Lowerbound)) + Lowerbound + 1 |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Feb 2005
Posts: 62
Rep Power: 4
![]() |
i'll try that, thanks.
edit: ok, it DOES work now, and i've just realized that my code is utter crap and under perfect circumstances it wouldn't really make a random string anyway lol back to the drawing board... Last edited by chepfaust; Feb 27th, 2005 at 3:49 PM. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
Don't forget to seed the generator:
randomize(timer) Best way of generating passwords in my opinion is to have a biggish text file of words (you can get all sorts with a little googling), and shove them together with a few other characters so you get more memorable things like south27cow and hello@cheese etc. |
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I take it you had a free Period 3?
|
|
|
|
|
|
#6 | |
|
Programmer
Join Date: Feb 2005
Posts: 62
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
It does exactly the same thing as just Randomize.
|
|
|
|
|
|
#8 |
|
Expert Programmer
|
What it does is.... random (sorry)
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Nov 2006
Posts: 3
Rep Power: 0
![]() |
I need a program created to generate phone # lists to be imported into a fax broadcasting program. The area code and exchange #'s are known, but I need a program to generate all of the possible combinations for the last four digits.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|