如何生成自动天气?
我必须创建一个自动天气,包括雨、雪、云、雾和晴天。
根据季节,我需要为所有天气设置一个百分比:天气预报一天会更新 3 到 4 次。
例子: 冬天 |雨:30% 雪:30% 晴天:10% 阴天:10%,雾:20%
我不知道如何根据百分比实现随机条件。有帮助吗?
非常感谢,并对我糟糕的英语感到抱歉。
I have to create an automatic weather including rain, snow, clouds, fog and sunny.
Depending on the season I need to set a percentage for all weather: the forecast will be updated 3 or 4 times during a day.
Example:
Winter | Rain: 30% Snow: 30% Sunny: 10% Cloudy: 10%, Fog: 20%
I do not know how to implement a random condition based on percentages. Some help?
Many thanks and sorry for my bad English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么,您可以使用:
只需查看 XML,看看您有哪些可用数据。
编辑
我第一次不明白OP想要什么。基本上,这更容易。
我建议的困难是将您的值保存在数组中(例如季节)以及出现一种或另一种天气的机会值。
使用
mt_rand(0,100)
获取随机值和上面的数组来确定天气。请告诉我这是否适合您。
Well, you can use:
Just take a look on the XML and see what data you have available.
EDIT
I didn't understand what the OP wanted the first time. Basically, it's even easier.
What I suggest tough, is to keep your values in arrays (for example the seasons) as well as the values for chances to have one type of weather or another.
Use
mt_rand(0,100)
to get a random value and the array above to determine the weather.Please let me know if this works for you.
Claudiu 的回答很好,但如果您想用华氏度 (F) 查看可能的示例,如下所示:
Great answer by Claudiu but if you want to view with Fahrenheit (F) that possible example Below: