473,785 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP mt_srand no longer seeds same number!!!!! aaarrrg

A
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? pleeeeeeaseeeee eee! :)
Sep 12 '08
20 5136
On Sep 12, 4:39*am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
And a "repeatable sequence of random numbers" is an oxymoron. *Yes, many
people have used a random number generator as a quick way to generate a
repeatable sequence. *I consider THAT a bug.
That's only because people are using the terminology colloquially.
What they mean is a "repeatable sequence of numbers which are
statistically random." It's entirely expected behavior that when
using the same seed one will get that. Especially if that's the
behavior of previous versions of the system.

However, http://www.php.net/manual/en/function.mt-srand.php does
state:

"Since 5.2.1 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."

The last sentence is quite important.

Walter
Sep 12 '08 #11
A
"Since 5.2.1 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."

I found somewhere on some forum that this is misstated. What this means is
that 5.2.0 and 5.2.1 will not produce the same sequence for the same seed,
however, the same seed will produce the same seq on specific php version in
other words, the sequences are not likely to change on future versions on
php e.g. 5.2.3, 5.2.6, 6.0 etc. but the seed will still function as it used
to.

anyway - the issue was somehow server related and not php related - the
administrator now fixed this script:

srand(42);
for ($i = 3; $i--;) echo rand()."<br />";
but my old one:

srand(1);
echo rand(0, 255)."<br />";
echo rand(0, 255)."<br />";
echo rand(0, 255)."<br />";

still produces random numbered sequences like srand is commented out. i'll
see if he can check that one out as well. i'll also ask him what was the
cause of this misbehaviour - maybe it is something to do with apache?
Sep 12 '08 #12
A
ok, here is the deal what happened here:

it appears that the latest build of suhosin module has an option to ignore
srand and mt_srand seeds and seed automatically. and the server php was
built with that option. where i used prebuilt module which obviously has
this option differently configured.

anyway, if anyone has an issue with that, now you know.
Sep 12 '08 #13
WalterGR wrote:
On Sep 12, 4:39 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>And a "repeatable sequence of random numbers" is an oxymoron. Yes, many
people have used a random number generator as a quick way to generate a
repeatable sequence. I consider THAT a bug.

That's only because people are using the terminology colloquially.
What they mean is a "repeatable sequence of numbers which are
statistically random." It's entirely expected behavior that when
using the same seed one will get that. Especially if that's the
behavior of previous versions of the system.

However, http://www.php.net/manual/en/function.mt-srand.php does
state:

"Since 5.2.1 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."

The last sentence is quite important.

Walter
They use it only because they've become accustomed to it being a
repeatable sequence. Such an assumption is incorrect.

PHP's implementation is now much closer to a true random number generator.

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

Sep 12 '08 #14
>PHP's implementation is now much closer to a true random number generator.

PHP's implementation is much closer to a live goat than it is to a
true random number generator. So is any other pseudo-random number
generator.

It's a *PSEUDO*-random number generator, and if you use cryptography,
the difference between a true random number generator and a
pseudo-random number generator can get you executed as a spy.
Sep 12 '08 #15
Gordon Burditt wrote:
>PHP's implementation is now much closer to a true random number generator.

PHP's implementation is much closer to a live goat than it is to a
true random number generator. So is any other pseudo-random number
generator.

It's a *PSEUDO*-random number generator, and if you use cryptography,
the difference between a true random number generator and a
pseudo-random number generator can get you executed as a spy.
When it comes to random number generators, NO language provides a real
one. They are all pseudo-random.

So you're saying anyone who uses cryptography on a computer should be
executed as a spy.

The world would be a very lonely place...

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

Sep 12 '08 #16
On Sep 12, 4:39 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>
>And a "repeatable sequence of random numbers" is an oxymoron. Yes,
many people have used a random number generator as a quick way to
generate a repeatable sequence. I consider THAT a bug.

That's only because people are using the terminology colloquially.
What they mean is a "repeatable sequence of numbers which are
statistically random." It's entirely expected behavior that when
using the same seed one will get that. Especially if that's the
behavior of previous versions of the system.
umm, no, not unless that was the design goal, which I don't think it was
or it wouldn't have been "fixed". Random is random is ... . A
randomizer that regenerates the same numbers is not creating truly
random numbers, is it?
>
However, http://www.php.net/manual/en/function.mt-srand.php does
state:

"Since 5.2.1 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."

The last sentence is quite important.
Sounds more like a weasel-out statement to me, admitting that the "fix'
might be a little iffy.
>
Walter


Sep 12 '08 #17
..oO(Jerry Stuckle)
>Gordon Burditt wrote:
>>PHP's implementation is now much closer to a true random number generator.

PHP's implementation is much closer to a live goat than it is to a
true random number generator. So is any other pseudo-random number
generator.

It's a *PSEUDO*-random number generator, and if you use cryptography,
the difference between a true random number generator and a
pseudo-random number generator can get you executed as a spy.

When it comes to random number generators, NO language provides a real
one. They are all pseudo-random.

So you're saying anyone who uses cryptography on a computer should be
executed as a spy.

The world would be a very lonely place...
No more problems finding a parking space. ;)

Micha
Sep 12 '08 #18
..oO(Twayne)
>On Sep 12, 4:39 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>>And a "repeatable sequence of random numbers" is an oxymoron. Yes,
many people have used a random number generator as a quick way to
generate a repeatable sequence. I consider THAT a bug.

That's only because people are using the terminology colloquially.
What they mean is a "repeatable sequence of numbers which are
statisticall y random." It's entirely expected behavior that when
using the same seed one will get that. Especially if that's the
behavior of previous versions of the system.

umm, no, not unless that was the design goal, which I don't think it was
or it wouldn't have been "fixed".
If it would have been a design mistake, then there wouldn't be a seed
function. But it exists, hence the previous behaviour was by intention.
>Random is random is ... . A
randomizer that regenerates the same numbers is not creating truly
random numbers, is it?
Truly random numbers require some more effort and can't be created with
software alone.

A software-based generator only creates pseudo-random numbers, based on
algorithms. Such algorithms are usually deterministic - same input, same
output.

Micha
Sep 12 '08 #19
>When it comes to random number generators, NO language provides a real
>one. They are all pseudo-random.
That's not an excuse to call any of them a true random number generator.

There are some hardware devices intended to generate random numbers
based on quantum theory (some built into Intel CPUs, for example).
Some operating systems give access to this, some through /dev/random.
Are there no languages that use the OS /dev/random?
>So you're saying anyone who uses cryptography on a computer should be
executed as a spy.
No, I'm saying that if they use crappy cryptography, they are more
likely to be CAUGHT and CONVICTED as a spy because their cryptography
is crappy.

Sep 12 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7381
by: Joe | last post by:
Hi, I have been working on some code that requires a high use of random numbers within. Mostly I either have to either: 1) flip a coin i.e. 0 or 1, or 2) generate a double between 0 and 1. I have utilised the following random number source code http://www.agner.org/random/ What I have found is that there is a problem with seeding. The code generates a seed based on time(0). I have found that I need to increment
4
2701
by: Jack | last post by:
I have two files: sort_comparison.c++ my_sort.h sort_comparison.c++ calls this code in my_sort.h: void my_sort::fillArray(int arr,int n) { // const int random_number_range=1000000;
70
6285
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like using the high-order bits returned by rand() instead of the low-order bits, avoiding using rand() for anything that wants decently random numbers, not using rand() if you want more than approx. UINT_MAX total different sequences, and so on. So I...
11
1841
by: Mark Rae | last post by:
Hi, My R&D department has asked me to look at threading in a Web Service written in C#, so I came up with the following code: using System; using System.ComponentModel; using System.Threading; using System.Web.Services;
6
5914
by: Intiha | last post by:
Hello all, I am trying to generate random seeds for my simulations. currently i was using srand(time(NULL); for this purpose. But for confidence in my results i ran it using a script in a loop. Since the time b/w execution is very similar, many simulation runs resulted in exact same results. Is there a better way of seeding the random number generator in c/c++
8
7559
by: Anil Gupte | last post by:
I had someone write a random number generator in C# (I am more of a VB programmer) and they came up with the following: public string GetRand(int count) { string number = ""; for (int i=0; i<count; i++) { Random Rnd = new Random(); number = number+Convert.ToString(Rnd.Next(0,9));
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.