以快速顺序生成2个随机数 [英] generate 2 random numbers in rapid sequence

查看:81
本文介绍了以快速顺序生成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个随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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