如何生成随机数而不重复上限?

时间:2018-04-20 19:55:16

标签: excel random google-sheets spreadsheet

我认为我已经达到随机生成数字的上限水平......有没有解决方法呢?我需要在一个公式/字符串中生成10个唯一的随机数,它总是必须是一个19位的数字。

我有这个: = TRUNC(兰德()*(9999999999999999999 - 1)+ 1)

但电子表格将其重写为: = TRUNC(RAND()*(9999999999999990000 - 1)+ 1) 所以我猜限制是9999999999999990000.是否有旁路? THX

EDIT1: A1中所需的输出格式:2459759093970314589,6393667943286134368,4897561254458152397等...

EDIT2:所以最后一个字符串是:

=CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))&","&CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))&","&CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))&","&CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))&","&CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))&","&CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))&","&CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))&","&CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))&","&CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))&","&CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*9+1);CONCAT(TRUNC(RAND()*10);TRUNC(RAND()*10)))))))))))))))))))

2 个答案:

答案 0 :(得分:1)

Excel中的数字精度是~15位有效数字。另一种方法是将随机数生成为字符串(第一个字符需要在1到9的范围内,其他字符在0到9的范围内)。像这样:

=CONCAT(
TRUNC(RAND()*9+1);
TRUNC(RAND()*10);
TRUNC(RAND()*10);
TRUNC(RAND()*10);
...
)

答案 1 :(得分:1)

enter image description here

=TRANSPOSE(regexextract(JOIN("",ArrayFormula(RANDBETWEEN(row(INDIRECT("a1:a"&A1*A2))^0-1,9))),rept("(\d{"&A1&"})",A2)))