- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
正在阅读:http://www.tldp.org/LDP/abs/html/randomvar.html
# If you need a random integer greater than a lower bound,
#+ then set up a test to discard all numbers below that.
FLOOR=200
number=0 #initialize
while [ "$number" -le $FLOOR ]
do
number=$RANDOM
done
echo "Random number greater than $FLOOR --- $number"
echo
# Let's examine a simple alternative to the above loop, namely
# let "number = $RANDOM + $FLOOR"
# That would eliminate the while-loop and run faster.
# But, there might be a problem with that. What is it?
我无法对上一条评论中的问题给出一个像样的答案。这就是我总是用其他语言(C/C++、Pascal)生成伪随机数的方式,并且没有任何问题——这是否只与 Bash 相关?
最佳答案
在您的随机数生成器可以为您提供刚好低于溢出点的值的编程语言中,后一个代码会有一个错误,其中项目在 MAXINT - FLOOR
和 MAXINT
会溢出。
Bash 没有这个错误,但您正在阅读的引用资料显然是在没有意识到这一点的情况下编写的。
关于bash - 在 bash 中使用 $RANDOM + $FLOOR 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23435810/
我有 floor(sqrt(floor(x))) .这是真的: 内部floor是多余的。 外floor是多余的。 最佳答案 显然,外层不是多余的,因为例如,sqrt(2)不是整数,因此 floor(s
如何将 floor 函数应用于 float 或 double 值以获得整数。我得到了 double 值:4.4497083717E10float Value:4.4497084E10 在我的函数中。我
这个问题在这里已经有了答案: Using bitwise OR 0 to floor a number (7 个答案) 关闭 6 年前。 我刚刚在一些 JavaScript 中看到了这个快捷方式。
PHP 中的 floor 函数行为异常。对于 16 个十进制值,它给出了下限值,但通过增加 1 个小数点来舍入。 $int = 0.99999999999999999; echo floor($int
这是我的 HTML: floor 1: {{Math.floor( value ) }} floor 2: {{value }} floor 3: {{value |
(floor) 在 C 中实际上是如何工作的?据 Techonthenet 报道。 com, In the C Programming Language, the floor function ret
我正在将我的 MATLAB 代码转换为 Excel 文档,但在转换以下公式时遇到困难。 x=(b/N)*(-floor(N/2):floor(N/2)) 如果例如 b =2 且 N = 5结果将是
与 math.floor 相比,使用整数除法运算符在性能上有什么好处吗? 7 // 2 结束 math.floor(7/2) 最佳答案 整数除法比 math.floor 函数调用快得多: >>> im
我有一个关于 Haskell 的问题 floor函数 - 它应该返回“不大于参数的最大整数”,但表达式 floor 3.9999999999999999 返回 4 而不是 3。它可能与 Double
我想用可变的十进制长度(在 iphone sdk 中)将小数点后的 double 取整。 这里有一些例子可以告诉你我的意思 NSLog(@"%f",[self floorMyNumber:34.524
我知道 float 通常会包含舍入误差。 当您取 float (或 double )的底限或上限以将其转换为整数时,结果值是否准确,或者“底限”值是否仍然是近似值? 基本上,像 floor(3.141
我正在尝试用 C++ 实现一个系统,我可以在其中判断数字是否为整数(小数点后的所有内容均为零)。为此,我使用了 if (sqrt(answer/2) == floor(sqrt(answer/2)))
我正在编写一段代码,我需要处理不一定在 0 到 1 范围内的 uvs(2D 纹理坐标)。例如,有时我会得到一个 u 分量为 1.2 的 uv。为了处理这个问题,我正在实现一个包装,它通过执行以下操作导
CREATE TABLE table_name (col_a double(10,2), col_b double(10,2), col_c double(10,2)); INSERT INTO ta
这个问题在这里已经有了答案: Why does Math.round(0.49999999999999994) return 1? (5 个答案) 关闭 8 年前。 我开发了一个 c++ 应用程序(
我需要一个函数来将正 double 四舍五入到最接近的整数。潜伏 aorund 我发现这种非常优雅的方式 int x = floor(y + 0.5); 我写了一个简单的测试程序: double a
在 C89 中,floor() 返回一个 double 值。以下是否保证有效? double d = floor(3.0 + 0.5); int x = (int) d; assert(x == 3)
floor() 函数向下舍入为最接近的整数。 语法 floor(x) 参数 描述 x 必需。一个数。 说
有谁知道方法/功能如何Int()或 floor()实现的? 我正在寻找以下相应的实现 abs()功能。 Int Abs (float x){ if x > 0 return x;
我的问题如下:log(1000,10) 返回 3,但 floor(log(1000,10)) 返回 2。如何解决这个问题? 我的 php 版本是 5.6.30-0+deb8u1。 最佳答案 因为 lo
我是一名优秀的程序员,十分优秀!