最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

加权随机数生成的C#

SEO心得admin70浏览0评论
本文介绍了加权随机数生成的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何能随机生成两种状态之一,与概率红色所产生的10%的时间,而绿色所产生的90%的时间?

How can I randomly generate one of two states, with the probability of 'red' being generated 10% of the time, and 'green' being generated 90% of the time?

每2秒一个绿色或红色指示灯将闪烁。

Every 2 second either a green or a red light will blink.

此序列将持续5分钟。

This sequence will continue for 5 minutes.

出现一个闪烁的光的总数应为300。

The total number of occurrences of a blinking light should be 300.

推荐答案

Random.NextDouble返回一个数字0和1之间,所以下面应该工作:

Random.NextDouble returns a number between 0 and 1, so the following should work:

if (random.NextDouble() < 0.90) { BlinkGreen(); } else { BlinkRed(); }
发布评论

评论列表(0)

  1. 暂无评论