making random numbers within a range

I am writinging a test program involving a hash table. I am suposed touse a for-loop to insert int 15 keys with random double values.

here's my insert method:

String s = "abcdefghijklmopqrstuvwxyz";
    public void insert(int key, double data)
    {
        probes = 0;
 if(fullTable())
     {
     System.out.println("table is full, cannot insert");
     }
 hashNode h = new hashNode(key, data);
 int index = hash(key);
 int attempt = 0;
 for(int i = 0; i < size; i++)
     {
  if(space[index] == null)
      {
   space[index] = h;  
   attempt++;
   probes++;
   System.out.println("probed " + probes + " times to insert " + s.charAt(key - 65));
   break;
      }
  else
      {
   if(space[index].getKey() == key)
       {
    space[index].setData(data);
    break;
       }
   index = rehash(key, attempt);  
   attempt++;
   probes++;
   System.out.println("probed " + probes + " times to insert " + s.charAt(key - 65));
      }
     }
 count++;
    }
 and heres my test so far:
import java.util.*;

public class hashTest2
{
  public static void main(String[] args)
  {
    Random r =new Random();
    myHash2 m = new myHash2(26);
   
    for(int i = 0; i < 15; i++)
    {
      m.insert(r.nextInt(25), r.nextDouble(20.0));    //note
    }
  }
}

where it says note: it gives me an error that says r.nextDouble cant be applie to (double)
also in the insert, I am supposed to convert the key int  to a char. I am using a String of the alphabet and using charAt(<int value>) I am stuck
Thank you
DAJones
DAJonesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
nextDouble() doesn't atke an arg and returns a value between 0 and 1.0

instead you should be writing:

r.nextDouble()*20.0
0
objectsCommented:
and you need to wrap the primitives to store in map:

m.insert(new Integer(r.nextInt(25)), new Double(r.nextDouble()*20.0));
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DAJonesAuthor Commented:
OK, now Im getting a stringIndexOutOfBounds error this has to be in my insert

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

objectsCommented:
actually ignore my comment about wrapping the primitive,I didn't notice you were using your own map implementation
0
objectsCommented:
check your hash function returns a value within the bounds of your array.
0
DAJonesAuthor Commented:
ok, heres what I'm doing im converting ints to chars. a = 65, b = 66, ... , z = 90. my code is working, but sometimes I'm getting values < 65, abd this is when I am getting the string out of bounds. but I thought my   System.out.println("probed " + probes + " times to insert " + s.charAt(key - 65)); lin would take care of this.
0
Mayank SAssociate Director - Product EngineeringCommented:
What happens if you use r.nextDouble () and multiply it with 65 (and ceil it)?
0
DAJonesAuthor Commented:
The data variable just needs to be a random double. I have no other restictions on this. I did solve my out of bounds problem by canging this line in my insert: from
System.out.println("probed " + probes + " times to insert " + s.charAt(key - 65));  to
System.out.println("probed " + probes + " times to insert " + s.charAt(key));
 and in the test this line:
m.insert(r.nextInt(90), r.nextDouble(20.0));  
to
int x = r.nextInt(25);
double  y = r.nextDouble * 20;
m.insert(x, y);  

it turns out I was combining two of my problems, on this one I dont need to convert! ha
thanks for the helpfull coments!
Dajones
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.