【发布时间】:2013-12-03 02:49:07
【问题描述】:
根据我的应用程序需要,我需要生成 0 到 1 范围内的数字,但需要稍作修改:
1. Range [0,1) : include 0 but not 1
2. Range (0, 1) : not include 0 nor 1
3. Range (0, 1] : same as 1. include 1 but not 0
4. Range [0,1]: include both 0 and 1
在 C# 中,我怎样才能像这样随机?
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
如果您正在创建一个
double-precision 随机数,那么恰好出现 0 或正好出现 1 的几率非常小。你到底想做什么? -
@Scony - 你建议的问题没有谈论结果的开放/封闭间隔......
-
@Alexei Levenkov - 对,但它显示了方法。如果您了解方法,则打开/关闭间隔是微不足道的