Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的要求是在给定区域生成一个随机点,即我有一个空间的 CGRect,我需要在这个矩形中生成一个 rendom 点。
在这种情况下我该如何进行?
您应该生成 2 个位于矩形范围内的随机值。
例如。像这样的矩形 (100,50,300,200) 将要求您获得 0 到 300(您的宽度)之间的 x 值,然后将 100 添加到它(您的原点)。y 值也需要相同的值,获取 0 到 200(高度)之间的随机值并添加 50(原点)。