Random number

C

Carolyn

Hi there

I'm having problems with generating random numbers, and would
appreciate any advice. I'm sure I'm doing something very simple wrong
but I've having been tring for ages and can't seem to get this
working.

I need to seed the randon number generator to a value(oldPosition) and
then produce a series of random numbers from this. I have given the
relevant code below

import java.util.*;

class Resolution
{
public void resolutionMethod(int oldPosition)
{
long seed = (long)oldPosition;
Random r = new Random(seed);

for (int i =0; i < 5; i++)
{
int nextNumber = r.nextInt();
System.out.println("random number " + i + nextNumber);
}
.......

I get the following error:

Resolution.java:14: Class Random not found.
Random r = new Random(seed);


Thanks
Carolyn
 
C

Chris Smith

Carolyn said:
I'm having problems with generating random numbers, and would
appreciate any advice. I'm sure I'm doing something very simple wrong
but I've having been tring for ages and can't seem to get this
working.

I get the following error:

Resolution.java:14: Class Random not found.
Random r = new Random(seed);

That doesn't look like an error message from any compiler I'm aware of.
What compiler are you using?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
P

Paul Lutus

Carolyn said:
Hi there

I'm having problems with generating random numbers, and would
appreciate any advice. I'm sure I'm doing something very simple wrong
but I've having been tring for ages and can't seem to get this
working.

I need to seed the randon number generator to a value(oldPosition) and
then produce a series of random numbers from this.

Just read the documentation, slowly and carefully.

import java.util.*;

public class Test {

public static void main(String[] args)
{

Random r = new Random();
r.setSeed(12345);
for(int i = 0;i < 20;i++) {
System.out.println(r.nextDouble());
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,272
Latest member
MaricruzDu

Latest Threads

Top