# random

I want to know how can clone an object in special position with random range or another type of random? I mean not in the center at zero, some where else.for example in where spawner there.

There are a couple of approaches you can do here. If you wanted them to spawn in specific random locations (like spawn points) you could keep a list of the spawn points and randomly choose one of them.

If it didn’t matter as much on specific spawn points you could use the Random.Range coupled with the Instantiate call to set the position of an object… something like,

``````void CloneRandomPosition(GameObject obj)
{
// get random positions for x,y,z
float randomX = Random.Range(0f, 100f);
float randomY = Random.Range(0f, 100f);
float randomZ = Random.Range(0f, 100f);

// create the new position
Vector3 newPosition = new Vector3(randomX, randomY, randomZ);

// set a default rotation
Quaternion newRotation = Quaternion.identity;

// clone the object at the random position
Instantiate(obj, newPosition, newRotation);
}
``````

You might try Random.insideUnitCircle(for 2D positioning) or Random.insideUnitSphere(for 3D positioning). Just use:

``````var newPos : Vector 3 = centerposition + Random.insideUnitCircle * maxRange;

Instantiate(gameObj,newPos,Quaternion.Identity);
``````

centerPosition would be the point at the center of the area in which the object should be placed. maxRange determines the limit for how far from center it can be placed. Just remember to consider if you want to place in 2 or 3 dimensions. If you are placing on a plane, then use insideUnitCircle. Otherwise, use insideUnitSpehere.