Generating unique random numbers in Excel using fo

2020-04-12 12:33发布

I have to generate five distinct random numbers from 0 to 50 using only formulas and not VBA. How should I do it?

2条回答
孤傲高冷的网名
2楼-- · 2020-04-12 13:03

Assuming A1 is blank or a text header you can use this "array formula" in A2

=SMALL(IF(COUNTIF(A$1:A1,ROW(INDIRECT("1:51"))-1)=0,ROW(INDIRECT("1:51"))-1),INT(RAND()*(51-ROWS(A$2:A2)+1)+1))

confirm with CTRL+SHIFT+ENTER so that curly braces like { and } appear around the formula in the formula bar, now copy to A6

That will generate 5 integers from 0 to 50 without repeats

查看更多
倾城 Initia
3楼-- · 2020-04-12 13:23

You may want to round the following depending on your use.

=RAND() * 50
查看更多
登录 后发表回答