gpt4 book ai didi

sql - Sql 函数 RAND() 中种子的用途是什么?

转载 作者:行者123 更新时间:2023-12-02 00:56:48 26 4
gpt4 key购买 nike

我知道 Rand() 用于生成小于 1 且大于 0 的随机数。如果您提供 seed ,它会在您每次执行时为同一连接中的同一种子生成相同的值。此外,select RAND(1),RAND() 每次您在同一连接中执行时,两者都会始终为您提供相同的结果集。

但是种子有什么用呢?

最佳答案

有点含蓄,但有据可查here :

Repetitive calls of RAND() with the same seed value return the same results.

For one connection, if RAND() is called with a specified seed value, all subsequent calls of RAND() produce results based on the seeded RAND() call. For example, the following query will always return the same sequence of numbers.

SELECT RAND(100), RAND(), RAND()

因此,SELECT RAND(1), RAND() 将返回相同的数字,而 SELECT RAND(), RAND() 则不会。

关于sql - Sql 函数 RAND() 中种子的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34062422/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com