その中にランダムポイントを返すRectangle
メソッドを持つクラスがあります。RandomPoint
次のようになります。
class Rectangle {
int W,H;
Random rnd = new Random();
public Point RandomPoint() {
return new Point(rnd.NextDouble() * W, rnd.NextDouble() * H);
}
}
しかし、それIEnumerable<Point>
を使用できるようになることを願っています。LINQ
rect.RandomPoint().Take(10)
それを簡潔に実装する方法は?