# .

Discussion in 'Plugin Development' started by elementalgodz11, Dec 10, 2013.

Not open for further replies.
1. Offline

.

2. Offline

### rocket138

Make a random number generator method that returns an int.
Then do something like (*world stuff*,1696.7 + randMethodHere(), 0 + randMethodHere(), 1176 + randMethodHere())

A simple google search will show you how to do random, I shouldn't need to explain it.
Random method should generate say 1-30 then just do -15 so it is a radius of like 15 up or down in each direction.

#2
3. Offline

### fireblast709

elementalgodz11 use the random as a percentage.
Code:
```double x = origin.getX() + ((random.nextDouble()*2)-1)*radius);
double z = origin.getZ() + ((random.nextDouble()*2)-1)*radius);
double y = (double)world.getHighestBlockYAt((int)x, (int)z);
player.teleport(new Location(world, x, y, z));
```
• random.nextDouble()*2 gets a number between 0 and 2
• -1 will make the number range between -1 and 1
• multiplying by the radius gives the range you like

#3
4. Offline

### Webster56

You want something like -15 to 15 for a 15 radius right ?
which means of course the diameter of your circle is 30

Multiply the nextDouble() by 30 to get a double in the [0,30] range and substract 15 to get a negative value for [0,15] results.

And as I've understood, the y value isn't random is it ?
Please tell us what errors do you get doing this

What you're looking for is getHighestBlockYAt(Location loc)

I believe the Location you've got to provide is your current (world, x + random x, y , z + random z)

EDIT by Moderator: merged posts, please use the edit button instead of double posting.

Last edited by a moderator: Jun 5, 2016
#4
5. Offline

### fireblast709

That happens when you just copy-paste :3

#5
L33m4n123 likes this.
6. Offline

### Louis1234567890987654321

double xUpperLimit=somevalue;
double xLowerLimit=somevalue;
double xDifference=xUpperLimit=xLowerLimit;
double xResult=(double)(random.nextInt((int)xDifference)+xLowerLimit) //do this with the y and z axis