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.