Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 27th, 2005, 2:15 AM   #1
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
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 If

i 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
chepfaust is offline   Reply With Quote
Old Feb 27th, 2005, 5:45 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Your random-number function is a little dodgy - it should do this:
Random = Int(Rnd * (Upperbound - Lowerbound)) + Lowerbound + 1
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 27th, 2005, 12:04 PM   #3
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
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.
chepfaust is offline   Reply With Quote
Old Mar 2nd, 2005, 5:31 AM   #4
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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.
Rory is offline   Reply With Quote
Old Mar 2nd, 2005, 5:19 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I take it you had a free Period 3?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 2nd, 2005, 10:10 PM   #6
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
Quote:
Originally Posted by Rory
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.
what does the "randomize(timer)" aspect do? i've just been using "randomize" to seed the generator, and it seems to work...
chepfaust is offline   Reply With Quote
Old Mar 3rd, 2005, 1:35 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
It does exactly the same thing as just Randomize.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 10th, 2005, 1:56 PM   #8
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
What it does is.... random (sorry)
Rory is offline   Reply With Quote
Old Nov 21st, 2006, 3:39 AM   #9
orez35
Newbie
 
Join Date: Nov 2006
Posts: 3
Rep Power: 0 orez35 is on a distinguished road
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.
orez35 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:02 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC