Post Reply 
VBS - Random Generating
Mar. 28, 2004, 01:07 AM
Post: #1
 
Hey guys I am currently using the folowing code to generate random characters on the ascii table 33-126.

Code:
Chr(Int(94 * Rnd)+33)

I need to have a line of code to randomly generate characters from the ascii table that aren't in a row. Like characters 33-52 and 56-126 and skip the characters 53-55.

Here is a link to an ascii table.

�{=(~�::[Shea]::��~)=}�
How 'bout you sideburns, you want some of this milk?
This fading text is pretty cool, eh? I bet you wish you had some.
Add Thank You Quote this message in a reply
Mar. 28, 2004, 01:43 AM
Post: #2
 
What do you mean by "in a row"?
Add Thank You Quote this message in a reply
Mar. 28, 2004, 02:07 AM
Post: #3
 
Like on the ascii table 33-126 is 'in a row' meaning there is no characters in between that I don't want. If I wanted all the characters minus the '@' symbol they wouldn't be in a row. I would have two sets 33-63 and 65-126 because the '@' symbol is character 64. I hope that clears it up for you.

�{=(~�::[Shea]::��~)=}�
How 'bout you sideburns, you want some of this milk?
This fading text is pretty cool, eh? I bet you wish you had some.
Add Thank You Quote this message in a reply
Mar. 28, 2004, 01:31 PM
Post: #4
 
I guess the easiest way would be to generate a random number between 0 and 1 using the same method as above...

Then have a line of code that generates a random number from 33 to 52, mulitply that by the number from the first generation (either a 0 or a 1), and add to that a random number from 56 to 126 multiplied by the inverse of the number from the first generation (either a 1 or a 0, the opposite of before)...

If the first number is a 0, the result of the addition/multiplication will merely be the random number from 33 to 52...

If the first number is a 1, the result will be the random number from 56 to 126...


Either that, or do a test and if 53 to 55 is the result of a random number from 33 to 126, just go back and generate another number until a non- 53 to 55 result kicks you out of the loop...
Add Thank You Quote this message in a reply
Mar. 28, 2004, 02:53 PM
Post: #5
 
No, they're not numbers they're ascii characters. On that link to the ascii table table, 33-126 is the decimal values of all the characters that appear on the keyboard, not the numbers 33-126.

�{=(~�::[Shea]::��~)=}�
How 'bout you sideburns, you want some of this milk?
This fading text is pretty cool, eh? I bet you wish you had some.
Add Thank You Quote this message in a reply
Mar. 29, 2004, 12:42 AM
Post: #6
 
Duh...

Chr(Int(94 * Rnd)+33)...

It's the CHR that converts the number generated to ASCII...

It could just as easily be Chr(Shea), where 'Shea' is a variable that is anything from 33 to 126...

And my above post is an algegraic means of defining 'Shea' to exclude 53 thru 55...
Add Thank You Quote this message in a reply
Mar. 29, 2004, 03:11 AM
Post: #7
 
Duh yourself. Thats the exact same code that I posted in my first post!

�{=(~�::[Shea]::��~)=}�
How 'bout you sideburns, you want some of this milk?
This fading text is pretty cool, eh? I bet you wish you had some.
Add Thank You Quote this message in a reply
Mar. 29, 2004, 10:50 AM
Post: #8
 
I know that!!!

My point is that YOU are creating a random NUMBER and then using CHR to convert that NUMBER to ASCII...

And that I am providing the algebra for that NUMBER to exclude 53 thru 55...
Add Thank You Quote this message in a reply
Mar. 29, 2004, 11:20 AM
Post: #9
 
Try this:
Code:
Shea = Int(91 * Rnd) + 33
If Shea > 52 then
Shea = Shea + 3
End If
Shea = Chr(Shea)
WScript.Echo Shea
OT: The forum's code tags don't allow for indents.
Add Thank You Quote this message in a reply
Mar. 29, 2004, 01:39 PM
Post: #10
 
Sorry ProxRocks, I didn't realize what you were saying. I think that will work Sidki. Thanx.

�{=(~�::[Shea]::��~)=}�
How 'bout you sideburns, you want some of this milk?
This fading text is pretty cool, eh? I bet you wish you had some.
Add Thank You Quote this message in a reply
Mar. 29, 2004, 07:00 PM
Post: #11
 
Shea;

Once again, you're giving us only a piece of the puzzle, and presumably you will integrate whatever solution we proffer into your overall efforts. As you've seen in other threads, we all tend to work more cohesively when you give us the big picture. I have to say that I do wish you'd get in the habit of sharing your overall goal with us, so that we can keep the idle chit-chat to a minimum. <_<

It appears to this broomstick cowboy that you are attempting to gather all of the characters that can be typed on the keyboard. Yet you are excluding the numerals 5, 6, and 7 - why is that? And if you are not interested in everything that can be entered via the keyboard, then please refer to my first paragraph.

Sorry if I sound like a pill, but I do tend to solve "big picture" puzzles whenever I can. Solving little bits and pieces without a clue as to where they fit in the grand scheme of things is not my strong suit.


Oddysey

I'm no longer in the rat race - the rats won't have me!
Add Thank You Quote this message in a reply
Mar. 29, 2004, 11:38 PM
Post: #12
 
The range of ascii characters was just example, I didn't mean for it to be specific numbers. I'm making a password generating type script. I can have it generate them with every character, but I need it to generate some with on lowercase and capital letters and some with only numbers and lowercase letters. Thats where my problem comes in. If you want to generate one with numbers and lowercase letters its harder because they are not in a row on the ascci table. They are the ranges 48-57 and 97-122. I can't figure out how to get it to skip the characters in between so it only generates lowercase and numbers.

PS - Sorry for my 'bad' habits. I'm taking classes to fix them. Big Teeth

�{=(~�::[Shea]::��~)=}�
How 'bout you sideburns, you want some of this milk?
This fading text is pretty cool, eh? I bet you wish you had some.
Add Thank You Quote this message in a reply
Mar. 30, 2004, 03:49 AM
Post: #13
 
Shea;

Keep taking that remedial class on "unburdening your soul", and you'll be fine. Big Teeth

I kinda thought it was something like this, except that I thought it was gonna be a file name or something. Who knew? [lol]

Most new programmers, when confronted with the need to limit a range like this, attempt to do so with simple arithmetic. In words of one syllable, doesn't work. Instead, go to the next higher level of math, and use the 'modulo' operator.

To review, modulo means to perform a division operation, and return the remainder portion of the quotient. Doing this in conjunction with your previous one-line code statement is easy:

chr(int(mod(91 * rand),33))

Notice that I divided 33 into whatever the random generator came up with; the rest you already know. Your assignment for the evening is to devise a way to limit the upper and lower bounds of your random number so that you achieve your goal of numbers, upper case, and lower case characters. The big hint is that you are not limited to the constants 91 and/or 33 - you may use a variable in either place.

Let us know what you come up with.

BTW, entering "generate random numbers" into Google brings more than 17,800 pages back. There might be something more concrete for you within the first 5 or 10 pages, who knows what you might find? Big Teeth


Oddysey

I'm no longer in the rat race - the rats won't have me!
Add Thank You Quote this message in a reply
Post Reply 


Forum Jump: