简体   繁体   English

如何在 Google 表格中创建非重复单元格/数字列表?

[英]How do I create a list of non-repeating cells/numbers in Google Sheets?

I'm trying to emulate Minesweeper in Google Sheets, and for this I want to create a second map adjacent to the first with all of the correct values already in it.我正在尝试在 Google 表格中模拟 Minesweeper,为此我想创建第二个 map 与第一个相邻,其中包含所有正确的值。 To randomize bomb position, I need a list of random numbers or cells(cells would be preferable).要随机化炸弹 position,我需要一个随机数或单元格列表(最好是单元格)。 However, I cannot figure out how to do this without ending up repeating numbers.但是,如果不结束重复数字,我无法弄清楚如何做到这一点。 The result would ideally be a vertical array of cell coordinates.理想情况下,结果将是单元格坐标的垂直数组。 Thank you!谢谢你!

Answer回答

The following formula should produce the result you desire:以下公式应该会产生您想要的结果:

=SORTN(FLATTEN(MAKEARRAY(10,10,LAMBDA(row,col,ADDRESS(row,col)))),20,,RANDARRAY(100),)

In =MAKEARRAY , change the first 10 to adjust how many rows to randomly choose from, or the second 10 to adjust how many columns to choose from.=MAKEARRAY中,更改前10以调整要从中随机选择的行数,或更改第二个10以调整要从中选择的列数。 The value in =RANDARRAY must be equal to the product of the number of rows and the number of columns. =RANDARRAY中的值必须等于行数和列数的乘积。 (eg in the above example, 10*10=100). (例如,在上面的例子中,10*10=100)。

Change the 20 to adjust how many randomly chosen values to return.更改20以调整要返回的随机选择值的数量。

Explanation解释

=MAKEARRAY is used to generate an array of every possible row and column combination. =MAKEARRAY用于生成每个可能的行和列组合的数组。 It accepts a =LAMBDA , which in this case is just the =ADDRESS function. The first two arguments of =MAKEARRAY determine how large the array should be, which is why changing them adjusts how many rows/columns to randomly pick from.它接受一个=LAMBDA ,在本例中它只是=ADDRESS function。 =MAKEARRAY 的前两个=MAKEARRAY确定数组应该有多大,这就是为什么更改它们会调整要从中随机选择多少行/列的原因。

Then, the result of =MAKEARRAY is squashed into a single column using the =FLATTEN formula.然后,使用=FLATTEN公式将=MAKEARRAY的结果压缩到单个列中。

Finally, the entire thing is sorted randomly using =SORTN combined with =RANDARRAY .最后,使用=SORTN结合=RANDARRAY对整个事物进行随机排序。 =SORTN also limits the number of results that are returned dependent on its second argument, which is why changing it adjusts how many results are returned. =SORTN还根据其第二个参数限制返回的结果数,这就是为什么更改它会调整返回的结果数。

If you want information on how to "freeze" the value of =RANDARRAY so it doesn't recalculate each time you change something, check out this question by player0.如果您想了解如何“冻结” =RANDARRAY的值,这样它就不会在您每次更改内容时都重新计算,请查看 player0 提出的这个问题

Functions used:使用的函数:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从没有有限行定义的工作表发送非重复电子邮件 - Sending non-repeating emails from sheets with no finite row definition 如何为Google表格中的两个单元格之间的if语句创建公式 - How can I create a formula for if statements between 2 cells in google sheets 如何为 Google 表格中的多个单元格创建 QR 码? - How can I create a QR code for multiple cells in Google Sheets? 如何依次填充Google表格中的大量单元格? - How do I sequentially fill a big range of cells in Google Sheets? 如何根据 Google 表格中的星期几突出显示单元格? - How do I highlight cells based on the day of the week in Google Sheets? 当相邻单元格在谷歌表格中为空时,如何列出非空单元格? - How to list non-empty cells when the adjacent cell is empty in google sheets? 如何通过 Google Script 从 Google 表格中的单元格将数字格式化为货币? - How to format numbers into currency by Google Script from cells in Google sheets? 谷歌表格如何创建一个公式来增加不包括文本单元格的单元格 - google sheets how to create a formula to increment cells excluding text cells 如何在 Google 表格中创建以逗号分隔的值列表 - How do I create a comma-separated list of values in Google Sheets 如何计算 Google 表格中非连续单元格中的任何文本? - How to count any text in non contiguous cells in Google Sheets?
 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM