how to use Random () to create circles in a frame

hello - i created a new Random() object...but how do i tell it a range of integers, to stay within?basically, i need to create many random circles within a frame...but i need to make sure that the circles created are drawn WITHIN window. please helpthanks!
[284 byte] By [sdomvillea] at [2007-11-27 1:56:46]
# 1

You can generate numbers in any range by using code like this:

// Do this once

Random rnd = new java.util.Random();

// Use rnd to get random numbers in a given range (starting from zero):

int rn1 = rnd.nextInt(50); // number in range 0..49

int rn2 = rnd.nextInt(25); // number in range 0..24

// And you can modify the range like this:

int rn3 = rnd.nextInt(50) + 50; // number in range 50..99

int rn4 = rnd.nextInt(25) + 1; // number in range 1..25

int rn5 = rnd.nextInt(201) - 100; // number in range -100..100

TimRyanNZa at 2007-7-12 1:31:33 > top of Java-index,Java Essentials,Java Programming...
# 2
Random myGen = new Random();int a = myGen.nextInt(5); // Generates a number from 0 - 4int a = myGen.nextInt(10) + 3; // Generates a number from 3 -
lethalwirea at 2007-7-12 1:31:33 > top of Java-index,Java Essentials,Java Programming...
# 3

yourRandom.nextInt(bound);

will return an integer between 0 and the bound.

For example, yourRandom.nextInt(5) will return something between 0 (inclusive) and 5 (exclusive)

if you want to have something between "x" (not being 0) and "y", y being > x then it's :

x+yourRandom.nextInt(y-x);

for example, to have something between 3 (inclusive) and 7 (exclusive):

3+yourRandom(7-3)

EDIT: sorry for the dup ^^

calvino_inda at 2007-7-12 1:31:33 > top of Java-index,Java Essentials,Java Programming...