PHP mt_srand不再是种子相同的号码!!!!! aaarrrg [英] PHP mt_srand no longer seeds same number!!!!! aaarrrg

查看:50
本文介绍了PHP mt_srand不再是种子相同的号码!!!!! aaarrrg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。


这是一个错误还是什么???


这里有一个简单的代码:


<?php

mt_srand(1);

echo mt_rand(0,255)。"< br />" ;

echo mt_rand(0,255)。"< br />" ;;

echo mt_rand(0,255)。" br / >" ;;

echo mt_rand(0,255)。"< br />" ;;

?>

每次运行时都会生成相同的序列。


但是......它不在Linux机器上的PHP 5.2.6上。


但是在我的测试环境(windows)上 - php 5.2.3确实可以正常工作!


那么我错过了什么?如何基于

mt_rand和mt_srand获得相同的随机序列?我需要基于起始种子的相同序列!


我查看了文档,它说:


PHP中的Mersenne Twister实现现在使用Richard Wagner的新种子

算法。

相同的种子不再产生与以前版本中相同的值序列

。 />
预计此行为不会再次发生变化,但仍然认为

不安全依赖它。

但是它说 - 在5.2.1之后---我有两个版本ABOVE 5.2.1 ...

怎么办?想法? pleeeeeeaseeeeeeee! :)

Hi all.

Is this a bug or what???

here is a simple code:

<?php
mt_srand(1);
echo mt_rand(0, 255)."<br />";
echo mt_rand(0, 255)."<br />";
echo mt_rand(0, 255)."<br />";
echo mt_rand(0, 255)."<br />";
?>

It should produce the SAME sequence every time when run.

however... it does not on PHP 5.2.6 on the linux box.

But on my test environment (windows) - php 5.2.3 does work properly!

So what am I missing? How do I get the same random sequences based on
mt_rand and mt_srand? I need same sequences based on starting seed!

I looked at the docs and it says:

The Mersenne Twister implementation in PHP now uses a new seeding
algorithm by Richard Wagner.
Identical seeds no longer produce the same sequence of values they did
in previous versions.
This behavior is not expected to change again, but it is considered
unsafe to rely upon it nonetheless.
but it says - AFTER 5.2.1 --- and I have both versions ABOVE 5.2.1...what to
do? ideas? pleeeeeeaseeeeeeee! :)

推荐答案

A写道:
A wrote:

大家好。


这是一个bug还是什么?


这里有一个简单的代码:


<?php

mt_srand(1);

echo mt_rand(0,255)。"< br />" ;;

echo mt_rand (0,255)。"< br />" ;;

echo mt_rand(0,255)。"< br />" ;;

echo mt_rand(0,255)。"< br />" ;;

?>


它应生成相同的序列每次运行时。


但是......在Linux机器上的PHP 5.2.6上没有。


但在我的测试中环境(windows) - php 5.2.3运行正常!


那么我错过了什么?如何基于

mt_rand和mt_srand获得相同的随机序列?我需要基于起始种子的相同序列!


我查看了文档,它说:


PHP中的Mersenne Twister实现现在使用Richard Wagner的新种子

算法。

相同的种子不再产生与以前版本中相同的值序列

。 />
预计此行为不会再次发生变化,但仍然认为

不安全依赖它。

但是它说 - 在5.2.1之后---我有两个版本ABOVE 5.2.1 ...

怎么办?想法? pleeeeeeaseeeeeeee! :)
Hi all.

Is this a bug or what???

here is a simple code:

<?php
mt_srand(1);
echo mt_rand(0, 255)."<br />";
echo mt_rand(0, 255)."<br />";
echo mt_rand(0, 255)."<br />";
echo mt_rand(0, 255)."<br />";
?>

It should produce the SAME sequence every time when run.

however... it does not on PHP 5.2.6 on the linux box.

But on my test environment (windows) - php 5.2.3 does work properly!

So what am I missing? How do I get the same random sequences based on
mt_rand and mt_srand? I need same sequences based on starting seed!

I looked at the docs and it says:

The Mersenne Twister implementation in PHP now uses a new seeding
algorithm by Richard Wagner.
Identical seeds no longer produce the same sequence of values they did
in previous versions.
This behavior is not expected to change again, but it is considered
unsafe to rely upon it nonetheless.
but it says - AFTER 5.2.1 --- and I have both versions ABOVE 5.2.1...what to
do? ideas? pleeeeeeaseeeeeeee! :)



我不知道5.2.3,但它按照5.2.6的设计工作。


随机数正好是 - 随机的(实际上,在编程中它们是
只能是伪随机的)。你的问题是你取决于重复序列的能力。这对于

任何语言来说都不是一个好的假设。


如果你需要能够重复序列,我建议你写一下

你自己的伪随机数生成器。这样你就可以控制它的行动了。他们不是太难了,谷歌搜索应该给你几个

的例子。


-

==== ==============

删除x来自我的电子邮件地址

Jerry Stuckle

JDS计算机培训公司
js ******* @ attglobal.net

==================

I don''t know about 5.2.3, but it is working as designed in 5.2.6.

Random numbers are exactly that - random (actually, in programming they
can only be pseudo-random). Your problem is you are depending on the
ability to repeat a sequence. That''s not a good assumption to make in
any language.

If you need to be able to repeat the sequence, I would suggest you write
your own pseudo-random number generator. That way you can control its
actions. They aren''t too hard, and googling should get you several
examples.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


刚刚发现srand和rand的行为方式相同!

5.2.3上的
它们生成相同的seq ...

5.2.6美元b $ b总是不同的不关心种子


不知道该做什么。怎么替换这个?这是一个PHP 5.2.6错误?或者

功能?
just discovered that srand and rand behave the same way!

on 5.2.3 they produce identical seq...

on 5.2.6 always different doesn''t care about the seed

dunno what to do. how to replace this? is this a php 5.2.6 bug? or a
feature?


随机数就是 - 随机(实际上,在编程中他们是
Random numbers are exactly that - random (actually, in programming they

只能是伪随机的)。你的问题是你取决于重复序列的能力。这不是用任何

语言做出的好假设。


如果你需要能够重复序列,我建议你写一下

你自己的伪随机数生成器。这样你就可以控制它的行动了。他们不是太难,谷歌搜索应该给你几个

的例子。
can only be pseudo-random). Your problem is you are depending on the
ability to repeat a sequence. That''s not a good assumption to make in any
language.

If you need to be able to repeat the sequence, I would suggest you write
your own pseudo-random number generator. That way you can control its
actions. They aren''t too hard, and googling should get you several
examples.



true但这只会使代码变得有用。种子

应该从同一点开始。是的,我需要随机数字,但

起点相同 - 这就是整个想法。谢谢你的答案。


其他任何想法?

true but that just bloats the code for something that should work. seed
should start from the same point. yes, i need random numbers but with the
same starting point - that''s the whole idea. thanks for the answer though.

any other ideas?


这篇关于PHP mt_srand不再是种子相同的号码!!!!! aaarrrg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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