Aura.Channel.World.Position.GetRandomInRect C# (CSharp) Метод

GetRandomInRect() публичный Метод

Returns random position in rect, centered on this position.
public GetRandomInRect ( int width, int height, Random rnd ) : Position
width int
height int
rnd System.Random
Результат Position
		public Position GetRandomInRect(int width, int height, Random rnd)
		{
			var x = rnd.Next(this.X - width / 2, this.X + width / 2 + 1);
			var y = rnd.Next(this.Y - height / 2, this.Y + height / 2 + 1);

			return new Position((int)x, (int)y);
		}

Usage Example

Пример #1
0
		public void GetRandomInRect()
		{
			var rnd = new Random(Environment.TickCount);
			var pos = new Position(10, 10);

			for (int i = 0; i < 10000; ++i)
			{
				var rndPos = pos.GetRandomInRect(10, 10, rnd);
				Assert.InRange(pos.X, 0, 20);
				Assert.InRange(pos.Y, 0, 20);
			}
		}