|
-
January 13th, 2003, 04:46 AM
#1
Random Password Generator
I have the following code for generating random passwords:
Code:
int RandomNumber(int Start, int End)
{
return (int)(Start + Math.random() * (End - Start));
}
String RandomPassword(String passwordSeed, int Length)
{
int i;
String s;
int x;
String temp = "";
for(i = 0; i < Length; i++)
{
x = RandomNumber(0,passwordSeed.length());
s = passwordSeed.substring(x,1);
temp += s;
}
return temp;
}
When I call the function RandomPassword it gives me StringIndexOutOfBoundsException 
What is the solution ? The index is generated correct (as far as I know). So there must be something else going wrong.
WM.
What about weapons of mass construction?
-
January 13th, 2003, 05:09 AM
#2
The second argument to String.substring(int beginIndex, int endIndex) is the end index of the substring - the substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Passing 1 for the end index means you're mostly asking for a substring of negative length...
I'm not afraid of dying - I just don't want to be there when it happens...
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
January 13th, 2003, 11:54 PM
#3
The best way to give would be
s=passwordseed.substring(x, x+1)
-
January 14th, 2003, 02:13 AM
#4
LOL, Yeah that did the trick Thanks for all the help.
P.S. Java isn't soo hard to learn
WM.
What about weapons of mass construction?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|