MySQL中RAND()的分布 [英] Distribution of RAND() in MySQL

查看:43
本文介绍了MySQL中RAND()的分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 MySQL 文档中的任何地方找到 RAND() 函数是否使用均匀分布.有人知道吗?

I can't find anywhere in the documentation of MySQL whether RAND() function uses a uniform distribution or not. Does anyone know?

推荐答案

一直没能快速找到函数的源代码;看到它可能有助于获得更好的答案.也就是说,它看起来像是不……但有点接近".

I haven't been able to find the source code for the function quickly; seeing it might help get a better answer. That said, it looks like a 'no.. but kinda close'.

从文档中我可以看到它试图是随机的(并且您可以选择播种它);但是有两个警告意味着当您期望它的第一个问题是在它的文档中时,它可能并不总是统一的:

From documentation I can see it tries to be random (and optionally you can seed it); but there are two caveats that mean it might not always be uniform when you expect it to the first issue is in it's documentation:

RAND() is not meant to be a perfect random generator. It is a fast way to generate random numbers on demand that is portable between platforms for the same MySQL version. 

即它的代码作为一个真正的随机数生成器是有问题的——它对于大多数用途来说已经足够好了,但不能被信任用于加密,我敢打赌,即使是统一的也不能被信任正如您所料.

i.e. the code for it is questionable in being a true random number generator - it's good enough for most purposes, but can't be trusted for use in, say, encryption, and I'd wager can't be trusted to even be as uniform as you may expect.

他们声称它并不完美意味着它几乎肯定会失败至少其中一些测试;如何仍然不清楚,但如果它不是完美的 RNG,您将不会看到完美均匀的分布;我希望更多/不常见的范围的差距或峰值.http://www.stat.fsu.edu/pub/diehard/cdrom/pscript/monkey.ps(此后还有其他工作,但这仍然是验证 RNG 的一些关键工作).

Their claim that it's not perfect means it will almost certainly fail at least some of these tests; the how is still unclear, but if it's not a perfect RNG, you won't see a perfectly uniform distribution; I'd expect either gaps or peaks of ranges that are more/less common. http://www.stat.fsu.edu/pub/diehard/cdrom/pscript/monkey.ps (there's been other work since but this is still some of the key work in validating RNG's).

打赌它背后的代码肯定试图保证均匀分布,因为这样做(跟踪已经出现的历史记录)会浪费大量内存.在任何情况下,如果您已经使用完美的 RNG 生成了很多值,则无法保证如果到目前为止您的值都很低,那么下一个值会很高.它总是一样随机..

It'd wager that code behind it certainly does not try to guarantee a uniform distribution, since to do so (track history of what's come up already) would waste masses of memory. In any case, if you've already generated a lot of values using a perfect RNG, nothing guarantees that if your values so far were all low the next one will be high. It will always be just as random..

这篇关于MySQL中RAND()的分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆