通过均匀分布生成具有不同颜色的相同类型的剂 - 任何logic
您好,
我正在尝试添加一个源,该源生成具有不同颜色的代理,这些颜色是根据不均匀分布随机填充的。例如,我希望看到该来源会产生50%的具有橙色或10%LightskyBlue颜色的代理商。 到目前为止,我有这条线,从 availablecolors 数组中随机选择颜色。但是我需要基于其相关概率选择每种颜色。
availableColors = { oliveDrab, crimson, orange, lightSkyBlue, darkOrchid }
agent.favoriteColor =
randomFrom(availableColors);
有线索吗?谢谢
Hello there,
I am trying to add a source that generates agents with different colors that are randomly populated based on a non-uniform distribution. For example, I'd like to see this source generates 50% of the agents having orange or 10% of them lightSkyBlue color.
I have this line so far that randomly selects a color from availableColors array. But I need each color to be selected based its associated probability.
availableColors = { oliveDrab, crimson, orange, lightSkyBlue, darkOrchid }
agent.favoriteColor =
randomFrom(availableColors);
Any clue? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从具有以下属性的代理调色板中创建自定义分发。在下面,2表示“无颜色”。如果您使用百分比,观察值的总和应始终为100。
然后创建一个具有以下属性和主体的函数:

最后,您现在可以使用:
现在允许您在任意数量的任何颜色和任何概率上自定义分布。
Create a custom distribution from the Agent palette with the following properties. In the below, 2 represents "no color". The sum of the number of observations should always be 100 if you are using percentages.
Then create a function with the following properties and body:

Finally, you can now use:
This allows you now to customize your distribution at any point to any number of colors and to any probabilities.
您应该以另一种方式进行操作:
myShapeHavingColor
You should do it the other way around:
myShapeHavingColor
如果您不满意编码,另一个简单的答案是使用选择的输出块。这样简单的东西:

Another simple answer if you're not comfortable with coding is to use the select output block. Something as simple as this:
