MS Access中的静态随机数 [英] Static Random Number in MS Access
问题描述
我正在使用以下公式来尝试创建静态随机数.
I am using the following formula in an attempt to create a static random number.
Random Number: Format(Int((99999999-11111111+1)*Rnd([Numbers]+11111111)))
但是,它返回一个不同的非静态随机数.
Yet, it returns a different non-static random number.
有什么建议吗?
推荐答案
您可以否定提供给 Rnd
函数为给定的种子值返回相同的随机数(也就是说,随机数和种子值之间的一对一映射):
You could negate the numerical argument supplied to the Rnd
function to cause the Rnd
function to return the same random number for the given seed value (that is, there would be a one-to-one mapping between the random numbers and the seed values):
语法
Rnd[(number)]
返回值
如果 number 是
-
小于零:每次使用相同的数字,使用数字作为种子.
大于零:序列中的下一个随机数.
Greater than zero: The next random number in the sequence.
等于零:最近生成的数字.
Equal to zero: The most recently generated number.
未提供:序列中的下一个随机数.
Not supplied: The next random number in the sequence.
?rnd(-2)
0.7133257
?rnd(-2)
0.7133257
?rnd(-3)
0.9633257
?rnd(-3)
0.9633257
但是,更好的方法可能是用静态随机数填充源表中的其他字段,或者构造一个单独的表,其中包含名称和名称之间的映射.随机数.
However, a better approach might be to either populate an additional field in your source table with the static random number, or construct a separate table containing the mapping between names & random numbers.
对于您的特殊情况,由于您希望生成8位随机数,因此可以使用:
For your particular case, since you are looking to generate 8-digit random numbers, you would use:
10000000 + Int(90000000 * Rnd(-[Names]))
这将产生一个介于10000000
至99999999
范围内的随机数.
This will yield a random number in the range 10000000
to 99999999
.
这篇关于MS Access中的静态随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!