生成独特的2列随机数的5000条记录 [英] Generate 5000 records in 2 columns of random number that being unique
问题描述
例如:
AB
----------------
1 98
1 23
37 98
6 56
93 18
。 。
。 。
。 。
谢谢
这是一个使用公式的简单的方法。
首先在公式选项卡中将计算选项设置为手动。
= RANDBETWEEN(1,100)
B将成为一个帮助列。在B2中输入以下内容: -
= RANDBETWEEN(1,99)
/ pre>
列C是您想要的第二个结果。将以下内容放在C2中: -
= IF(B2< A2,B2,B2 + 1)
根据需要拉下公式。
每次按现在计算,你会得到一组新的随机数。
但是,如果您真的需要独特的行(每一行都不同),则需要一种不同的方法 - 可以生成一组的4位数字,将它们分成第一个和最后一对数字,并过滤掉第一个和第二个数字的数字。
生成A2中的4位数字: -
= RANDBETWEEN(1,9998)
在B2中输入第一个两位数的加号: -
= INT (A2 / 100)+1
取第二个2位数字加上C2中的一个: -
= MOD(A2,100)+1
C在D2中出现无效数字: -
= OR(ISNUMBER(MATCH(A2,A $ 1:A1,0)), B2 = C2)
在E2中设置有效号码的总计: -
= COUNTIF(D2:D $ 2,FALSE)
这是第二种方法在检查一行中重复行以及重复数字时的外观。请注意,您必须生成约3,000行才能获得2,500个不同的行: -
How I can generate 5000 records in 2 columns of random numbers between 1 and 100 that being unique.
For example:
A B ---------------- 1 98 1 23 37 98 6 56 93 18 . . . . . .
thanks
解决方案Here is a simple-minded approach using formulae. Whether it would be appropriate would depend on context.
First in the Formulas tab set calculation options to 'Manual'.
Put the following formula in a2:-
=RANDBETWEEN(1,100)
B is going to be a helper column. Put the following in B2:-
=RANDBETWEEN(1,99)
Column C is the second result that you want. Put the following in C2:-
=IF(B2<A2,B2,B2+1)
Pull the formulae down as required.
Each time you press 'Calculate Now', you will get a fresh set of random numbers.
However if you really need unique rows (every row to be different) you'd need a different approach - could generate a set of 4-digit numbers, split them into first and last pairs of digits and filter out ones where first and second were equal.
Generate the 4-digit number in A2:-
=RANDBETWEEN(1,9998)
Take the first two-digit number plus one in B2:-
=INT(A2/100)+1
Take the second 2-digit number plus one in C2:-
=MOD(A2,100)+1
Check for invalid numbers in D2:-
=OR(ISNUMBER(MATCH(A2,A$1:A1,0)),B2=C2)
Set up a running total of valid numbers in E2:-
=COUNTIF(D2:D$2,FALSE)
Here's how the second approach would look with checking for duplicate rows as well as duplicate numbers within a row. Note that you'd have to generate about 3,000 rows to get 2,500 distinct rows:-
这篇关于生成独特的2列随机数的5000条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!