乘以随机数 [英] Multiplying Random Numbers

查看:130
本文介绍了乘以随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定是否可以使用随机函数将我在Access中生成的两个字段相乘。结果似乎总是另一个随机数,它使用与前两个字段相同的范围。


Ex。 Expr 1:Int((6-3 + 1)* Rnd()+ 3)* 100

Expr 2:Int(((2-1 + 1)* Rnd()+ 1)) * 3


我希望能够返回使用这些数字生成的数字的结果,但如果我直接尝试:


Expr 3:[Expr 1] * [Expr 2]它只返回一个与这些数字使用相同范围的随机数。

Hi, I am trying to determine if it is possible to multiply two fields that I have generated in Access using the random function. The result always seems to be another random number which uses the same range that I have for the two previous fields.

Ex. Expr 1: Int((6-3+1)*Rnd()+3)*100
Expr 2: Int(((2-1+1)*Rnd()+1))*3

I want to be able to return the result of the numbers that were generated using these, but if I try the straight forward:

Expr 3: [Expr 1]*[Expr 2] it just returns a random number that uses the same range as those numbers.

推荐答案

你发布了什么并不是真正有意义的东西,特别是当你保留了应该简化的(6-3 + 1)等表达式时。


Expr 1简化为100 * Int (3 +(4 * Rnd)),它将生成一个范围为300-700的随机数.Expr 2只是3 * Int(1 +(2 * Rnd)),这将生成3范围内的随机数 - 9.将两个表达式相乘将产生一个900 - 6300范围内的随机数,这可能是由任意事件中的单个表达式生成的。


Rnd函数将生成新的随机数每次调用时都会出现bers - 这些与单个表达式中的不同,因此(Expr 1 * Expr 2)将与两个原始计算的乘积不同。由于生成的随机数范围将在上述范围内(900 - 6300),问题是什么?


所提到的范围必须具有一定的意义正在做,但你没有解释他们的意思或为什么你需要这些范围界限。


-Stewart
What you have posted is not really something that makes much sense, particularly when you have retained expressions such as (6-3+1) which should have been simplified out.

Expr 1 simplifies to 100 * Int(3 + (4 * Rnd)), which will generate a random number in the range 300 - 700. Expr 2 Is just 3 * Int(1 + (2 * Rnd)), which will generate a random number in the range 3 - 9. Multiplying the two expressions will generate a random number in the range 900 - 6300, which could have been generated by a single expression in any event.

The Rnd function will generate new random numbers on every occasion it is called - these will not be the same as in the individual expressions, so (Expr 1 * Expr 2) will not be the same as the product of the two original calculations. As the range of the random number generated will be within the bounds stated above (900 - 6300), what''s the problem?

The ranges mentioned must have some significance in whatever you are doing, but you haven''t explained what they mean or why you need these range boundaries.

-Stewart


有趣,我会增加惊喜(至少对我来说)。我希望结果值能够被SQL引擎保存和重用,而不是简单地保存要重新评估的公式。当然很有意思。
Interesting, and I would add surprising (to me at least). I would have expected the resultant values to be saved and reused by the SQL engine rather than simply saving the formulas to be re-evaluated. Certainly interesting.


@Swart:

如果我弄错了,请原谅我,但不是你的上限,因为Rnd()永远不会返回值1:
@Stewart:
Forgive me if I am mistaken, but aren''t your Upper Ranges off, since Rnd() can never return a Value of 1:
展开 | 选择 | Wrap | 行号


这篇关于乘以随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆