Create a randomly generated password from the selected character sets.
David Newton wrote:Be careful where you put your curly braces and beware of off-by-one errors.
I'm curious what Java book is being used or where you're getting some of your syntax ideas from--it might be worth reviewing the basics of Java expressions.
When you do things right, people won't be sure you've done anything at all.
David Newton wrote:@Janice: Not really; you can only switch on constants--not ranges.
When you do things right, people won't be sure you've done anything at all.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:because this is meaningless:
int randomNumber = ((int)(0+ Math.random()* 65 - 90 || 97 - 122 || 48- 57 || 58 - 63));
the "||" means a boolean OR. the only allowed values on either side are TRUE or FALSE. You have integers.
I understand what you are trying to do, but Java does not support it. when Java sees something like "97 - 122", it sees that as a mathematical expression that must be evaluated - and does so to make this "negative twenty five".
so now you have
int randomNumber = ((int)(0+ Math.random()* -25 || -25 || -9 || -5 ));
Java then tries to evaluate the 'ORs'. -25 OR -25 is not valid - there's some value other than TRUE or FALSE on either side.
Note: What i wrote is not techinically correct, as I believe the * will have precedence, so you'll actually end up with
int randomNumber = (<something> - 90 || -25 || -9 || -5 ));
where <something> is whatever "(int)(0+ Math.random()[b]* 65" evaluates to - and that will be different each time.
When you do things right, people won't be sure you've done anything at all.
nathan gibson wrote:
but when i need more that one type ex: lowercase and uppercase the statement:
int randomNumber = ((int)(0+ Math.random()* 65 - 90 || 97 - 122)); wont work.
"ye shall know the truth & the truth shall set you free..."
Henry Wong wrote:You still have the same problem -- with all of your loops.
If lowercase is true, you code will enter the loop. In this loop, you change the password and counter variable, but lowercase is not changed -- hence, this will be an endless loop.
In other words, if any of the loops in your program runs, it will just keep running those loops forever.
Henry
the reason i am asking is because i am trying to use both capital and lowercase letters from the ascii chart and i dont know how to make a random number that will cycle through both of these but skip over the characters that are in the middle.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Garrett Rowe wrote:Or you can dispense with the 'magic' ASCII numbers altogether and do something like this:
Henry Wong wrote:
the reason i am asking is because i am trying to use both capital and lowercase letters from the ascii chart and i dont know how to make a random number that will cycle through both of these but skip over the characters that are in the middle.
I don't think that it is possible to do it with one formula expressions. Two options...
1. Generate a random number that is the size of the two ranges (lowercase and capital) combined. Using the value of the random (greater or less than a certain value), either process it as lower or upper (ie. two different formulas).
-- or --
2. Use the while loop, as you had before -- but get it working. Generate the number, if it is valid, exit the loop. Otherwise, loop and try again.
Henry
nathan gibson wrote:
Garrett Rowe wrote:Or you can dispense with the 'magic' ASCII numbers altogether and do something like this:
i like your thinking, but i think that would be frowned apon.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
nathan gibson wrote:
im not quite sure how this is supposed to go.
Consider Paul's rocket mass heater. |