Re: Random number generator


[ Follow Ups ] [ Post Followup ] [ K-State KDD Lab Research Discussion Forum ] [ FAQ ]

Posted by Laura Kruse on January 10, 2001 at 23:35:24:

In Reply to: Random number generator posted by Haipeng Guo on January 10, 2001 at 23:34:25:

: Dear all,

: Is there anybody who has used the Random Class in Java.util.Random? How random is it? I want to use it generate random doubles, uniformly distributed between 0.0 and 1.0. Do you have any idea how random and uniform it (the random numbers generated by Java.util.random) is? Thank you very much for any suggestions!

: -hpguo

Yeah, I did when I was working on the pullinput thing that takes the
*.dat files and produces other files from it.

Here's a code snippet for what you probally want. It gives me random
numbers. :)

Vector data;
Random random;

int rand;
String tmp;

data = new Vector();
random = new Random();

[...snip...]

for(int i=0;i<100;i++) {
rand = java.lang.Math.abs(random.nextInt(data.size() - 1));
tmp = (String) data.elementAt(rand);

[...snip...]
}

I hope that helps. :) That gives me a positive random number between 0
and data.size() - 1.

--
Laura


Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ K-State KDD Lab Research Discussion Forum ] [ FAQ ]