Author |
Message |
Prince
|
Posted: Thu Feb 19, 2004 11:07 am Post subject: random integers |
|
|
how do u get them? i had sum code but it disappeared |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Thu Feb 19, 2004 7:18 pm Post subject: (No subject) |
|
|
code: | import java.lang.*;
import java.io.*;
import java.util.*;
class Test
{
long randomNumberSeed = System.currentTimeMillis();
Random randomNumberGenerator = new Random(randomNumberSeed);
int randomInt = randomNumberGenerator.nextInt();
} |
See the Sun Java docs for the Random class. |
|
|
|
|
|
Prince
|
Posted: Fri Feb 20, 2004 10:18 am Post subject: (No subject) |
|
|
isnt there a simpler way |
|
|
|
|
|
Tony
|
Posted: Fri Feb 20, 2004 2:12 pm Post subject: (No subject) |
|
|
looks preaty simple to me... once you declear your randomNumGen, its just
code: |
randomNumberGenerator.nextInt();
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
rizzix
|
Posted: Fri Feb 20, 2004 5:08 pm Post subject: (No subject) |
|
|
even simpler? hmm...
|
|
|
|
|
|
wtd
|
Posted: Fri Feb 20, 2004 6:18 pm Post subject: (No subject) |
|
|
rizzix wrote:
Yeah, I knew someone would beat me to that answer, so I posted the other answer.
Really, though, use either one, but know the Random class. It's more powerful and flexible than Math.random(). |
|
|
|
|
|
|