Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
rand
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以在 自定义过滤条件 和 表计算 中使用 rand 函数,以返回介于 0 和 1 之间的随机数。
语法
rand()
rand 函数会返回介于 0 和 1 之间的随机数。
示例
rand 函数通常用于生成随机整数,有时用于选择随机数据抽样。例如,如需生成介于 1 和 100 之间(含边界值)的整数,您可以使用:
(floor(rand()*100)+1)
此表达式的工作原理如下:
- 使用
rand() 函数生成介于 0 和 1 之间的随机数。
- 乘以 100,将其转换为介于 1 和 100 之间的随机数。
- 使用
floor 函数将随机数向下舍入到最接近的整数,生成介于 0 和 99 之间(含边界值)的随机数。
- 加 1,将随机整数提升到 1 到 100 之间(含边界值)。
然后,您可以过滤查询,以仅包含低于特定随机数的数据。
注意事项
rand 函数会生成一个包含 16 位小数的数字,例如 0.04277424614631747。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-05-10。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2026-05-10。"],[],[]]