I am trying to generate two random numbers that are apart by atleast 2 numbers, in order to create a random substring of atleast two characters.. I have spent four hours trying to figure it out to no avail.. help please!

- 09-23-2009, 06:24 AMruby&oliverNeed help generating random numbers atleast 2 characters apart
I am trying to generate two random numbers that are apart by atleast 2 numbers, in order to create a random substring of atleast two characters.. I have spent four hours trying to figure it out to no avail.. help please!

- 09-23-2009, 06:35 AMFubarable
Hello, and welcome to our forum! Let's see what you have so far so we can see what you may be doing right and may be doing wrong. Please don't forget to use code tags when posting code (please see my signature after this post in blue text). Much luck!

- 09-23-2009, 06:40 AMDieter
Have you looked at the Math.random() function on the API?

you can also have a look at this site

Java: Random numbers - API - 09-23-2009, 06:42 AMruby&oliver
Thanks for the heads up, I did not want to post my code, because I ws not sure about the tags... here is what I have for the random part.. the rest is long so I don't want to post the whole thing.

Code:`Random random = new Random (seed);`

int start = 0, end = strng.length();

int random1 = random.nextInt( end - start + 1) + start;

int random2 = random.nextInt( end - start + 1) + start;

int min = Math.min(random1,random2);

int max = Math.max( random1,random2 );

Thanks - 09-23-2009, 06:43 AMDieter
Or are you Stuck at the "atleast 2 characters apart" ?

- 09-23-2009, 06:45 AMruby&oliver
Hi Dieter, I did see that and many other help sites. I guess I am just not sure how to incorporate any of those methods into the Random function to make them atleast 2 apart.

Thanks for the reply. - 09-23-2009, 06:45 AMDieter
Ok my bad for not understanding you, i'm off to school now... will try to look at it there :p

- 09-23-2009, 06:48 AMDieter
i think i got someting simular on a test. but the project is on the computer in my school. will post some code around 9.00

Hopefully you will have an answer by then...

sorry i can't help you instant

Best of luck,

Dieter - 09-23-2009, 06:50 AMruby&oliver
Thanks for the help.. been going crazy for the last four hours trying all different methods that do no work....

- 09-23-2009, 09:34 AMDieter
Can you post a code you tried?

- 09-23-2009, 09:45 AMruby&oliverCode:
`Random random = new Random (seed);`

int start = 0, end = strng.length();

int random1 = random.nextInt( end - start + 1) + start;

int random2 = random.nextInt( end - start + 1) + start;

int min = Math.min(random1,random2);

int max = Math.max( random1,random2 );

System.out.print("The string between " + random1 + "and" + random2 + "is: ");

- 09-23-2009, 10:13 AMDieter
I donno if this is what you need but i got someting that might help you.

This example shows you the numbers between -10 and -5...

Code:`int [] generate = new int[50];`

for (int i = 0; i < generate.length; i++) {

generate[i] = (int)(Math.random() * 5) - 15;

System.out.println(generate[i]);

}

- 09-23-2009, 10:14 AMDieter
you can play with this kind to work your way to yours.

else i didn't get your question

all the best,

Dieter