以快速顺序生成2个随机数

编程入门 行业动态 更新时间:2024-10-27 16:24:07
本文介绍了以快速顺序生成2个随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要从PHP或 mysql快速生成2个随机数。 我无法做到。我从PHP的mt_rand()和mysql的RAND()获得了相同的数字 。 任何想法? 我想我可以使用当前的rancom号作为下一个 随机数的种子。但这真的有用吗?

I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP''s mt_rand() and from mysql''s RAND(). any ideas? I suppose I could use the current rancom number as the seed for the next random number. but would that really work?

推荐答案

使用电脑的人经常会谈论他们的系统随机 数字发生器和随机数它产生。但是,由计算机通过确定性过程计算出的数字不能通过 定义来随机。鉴于用于创建 数字及其内部状态的算法的知识,您可以预测 后续调用算法返回的所有数字,而使用真正的随机数字, 对一个数字或任意长的数字序列的了解是没有的。 用于预测下一个要生成的数字。 计算机生成的随机数字更恰当地称为 伪随机数,以及这些数字的伪随机序列。已经开发了各种聪明的算法,它们可以生成 数字序列,这些数字通过了用于区分随机 序列的每个统计测试。一些模式或内部订单。 PHP有许多内置随机函数,如rand()。这个函数 必须首先由srand()播种才能正常工作。 <?php //数字范围 //最小数量 People who work with computers often talk about their system''s "random number generator" and the "random numbers" it produces. However numbers calculated by a computer through a deterministic process, cannot, by definition, be random. Given knowledge of the algorithm used to create the numbers and its internal state, you can predict all the numbers returned by subsequent calls to the algorithm, whereas with genuinely random numbers, knowledge of one number or an arbitrarily long sequence of numbers is of no use whatsoever in predicting the next number to be generated. Computer-generated "random" numbers are more properly referred to as pseudo-random numbers, and pseudo-random sequences of such numbers. A variety of clever algorithms have been developed which generate sequences of numbers which pass every statistical test used to distinguish random sequences from those containing some pattern or internal order. PHP has a number of inbuilt random functions such as rand(). This function must be first seeded by srand() in order for it to work properly. <?php // Range of numbers // Minimum number

min =" 1"; //最大数量 min = "1"; // Maximum number

max =" 10"; srand(( double)microtime()* 1000003); // 1000003是素数 echo" rand()伪随机数"。br /> rand( max = "10"; srand((double) microtime() * 1000003); // 1000003 is a prime number echo "rand() pseudo-random number". rand(

更多推荐

以快速顺序生成2个随机数

本文发布于:2023-11-30 18:08:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651014.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:随机数   顺序   快速

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!