gpt4 book ai didi

c++ - Oracle 数据库中的 urand

转载 作者:搜寻专家 更新时间:2023-10-30 22:28:31 24 4
gpt4 key购买 nike

我正在使用 Oracle Database 12c。有没有办法像我们在 C++ 中那样生成均匀分布的 float (urand() )?

或者任何可以这样做的子程序。 DBMS_RANDOM 包具有正态分布但不均匀分布的功能

最佳答案

DBMS_RANDOM.VALUE 生成均匀分布的值。

虽然the manual没有明确说明 VALUE 如何随机化数字我认为我们可以确信它使用均匀分布,因为:

  1. 这是最简单的方法,并且已经有另一个函数可以提供标准化分布。
  2. 下面的快速测试用例验证了数字看起来是均匀分布的。

对于测试,设置一个种子以便每个人的结果都匹配:

begin
dbms_random.seed(val => 'abcd');
end;
/

对于测试代码,生成100,000个随机值,统计它们,然后四舍五入分桶:

--Compare DBMS_RANDOM.NORMAL and DBMS_RANDOM.VALUE.
select normal_value, normal_count, value_count
from
(
--NORMAL
select round(random_value, 1) normal_value, count(*) normal_count
from
(
select
dbms_random.normal random_value
from dual
connect by level <= 100000
)
group by round(random_value, 1)
order by normal_value
) normal_values
join
(
--VALUE
select round(random_value, 1) value_value, count(*) value_count
from
(
select
dbms_random.value(-3,3) random_value
from dual
connect by level <= 100000
)
group by round(random_value, 1)
order by value_value
) value_values
on normal_values.normal_value = value_values.value_value
order by 1;

将值导出到 LibreOffice,然后您也可以生成这个丑陋的图表:

enter image description here

关于c++ - Oracle 数据库中的 urand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47941648/

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