Page 3 of 5
Re: Here is a reason why not to use rand().
Posted: Tue Dec 30, 2008 6:57 pm
by Eran
Quantum computers should be able to give us real randomness (ie, they are not deterministic as conventional computers are)
Re: Here is a reason why not to use rand().
Posted: Tue Dec 30, 2008 7:10 pm
by Christopher
jshpro2 wrote:I still hold my statement mt_rand is less predictable than rand by current computers or humans, randomness is an illusion though, it'd be like trying to write a program that can find gold at the end of a rainbow.
Wait a second ... I think we agree that mt_rand() produces a number sequence that is less predictable than rand(). But then you jump on this "randomness is an illusion" idea when you just said that one function is less predictable than another? Randomness is not like finding something imaginary -- it is completely quantifiable! As it relates to these functions, randomness means the lack of predictability (and not some moral or causal meaning). You seem to be disagreeing with yourself, not Kai!

Re: Here is a reason why not to use rand().
Posted: Tue Dec 30, 2008 7:58 pm
by josh
In the original picture, rand _looks_ less random because we can see the patterns in the shades of the line as its drawn left to right, however the mt_rand image looks "less random" to a human, and subsequently the machines the humans built find it "harder" to find the pattern. All I'm saying is given 2 data sets, one seeded with rand and one seeded with mt_rand, you could still do a heuristic -like algorithm that could detect patterns, there is underlying formulas that operate under non-random laws, we just layer code ontop of that that produces something that "looks" random. Random is a human concept, its just an concept we assign when we can't detect the patterns, built in to stop us from searching for something we won't find. Given enough time a computer could come up with a formula when applied to each dot in the mt_rand image, would form a 2nd projection that "looked" less "random".. and would ultimately be able to come up with it's own source code for mt_rand, that given the same seeds would produce the same outputs, the same reason you see patterns in the rand image is the same reason you would see patterns in the mt_rand image, if your brain had the sheer amount of power to detect them. the quantifiable difference is in the amount of computations ( electrical or psychological ) are needed before the pattern is detected, a human would give up after a few seconds or minutes ( lets hope ) but theoretically if a program with enough computational power behind it were to keep transforming the projection into different polynomial spaces, a linear pattern would have to form... its like brute forcing a hash, the hash is "uncrackable" but that doesn't mean people will find a way to get the solution they need, by solving a related problem that simulates the "real problem".
If you mean by random: entropy, then nevermind.
Re: Here is a reason why not to use rand().
Posted: Tue Dec 30, 2008 9:25 pm
by Eran
jshpro is right that normal computer simulations for random numbers are deterministic - meaning, they are just very long sequences of predetermined numbers and not random element at all. It's just that the pattern repeats after many many numbers, so it appears pseudo random for quantities that are not of the scale of its pattern.
Re: Here is a reason why not to use rand().
Posted: Tue Dec 30, 2008 10:06 pm
by Christopher
jshpro2 wrote:If you mean by random: entropy, then nevermind.
It seems that you are talking about random and I am talking about randomness. All of your definitions describe randomness as I know it. I think you are saying that there is no ultimate random. I think I am saying that that concept is unrelated to this thread.
Re: Here is a reason why not to use rand().
Posted: Tue Dec 30, 2008 10:13 pm
by josh
Randomness is a lack of order, purpose, cause, or predictability - which is the meaning I think everyone is referring to. I'm saying it has everything to do with this thread

Re: Here is a reason why not to use rand().
Posted: Wed Dec 31, 2008 7:47 am
by omniuni
The truism of randomness aside, I think both the second code sample as well as the first shows the weakness quite well.
There's a very clear cross-hatch pattern, much like what I'm used to with QBasic. I think, kaisellgren's code shows the pattern more noticeably, but the fact that there is a noticeable pattern when there shouldn't be at all is enough to make rand() problematic.
As for the topic of randomness, while it is true that today's computers use algorithms to generate random numbers, the purpose of a random number generator is to find a next value that does NOT fit with any known pattern. Funny, really, how we can use a pattern that by avoiding we can produce a pattern of unrelated values.
eh!?
Re: Here is a reason why not to use rand().
Posted: Wed Dec 31, 2008 7:59 am
by kaisellgren
omniuni got the point of this thread.
pytrin: jshpro is right that normal computer simulations for random numbers are deterministic - meaning, they are just very long sequences of predetermined numbers and not random element at all. It's just that the pattern repeats after many many numbers, so it appears pseudo random for quantities that are not of the scale of its pattern.
In real life, random is just a very long sequences of predetermined actions and phenomenoms. In computers, they are much much shorter.
Nothing is truly random. Nothing. That's not the point in here though. The point was not to show how random rand() is. The point was to show how much better scalability mt_rand() has over rand(). Eventhough this "scalability pattern-like issue" is not something that occurs easily, it's still clear how much more limited is rand().
Re: Here is a reason why not to use rand().
Posted: Wed Dec 31, 2008 10:43 am
by Christopher
Random may be jshpro2's pot of gold in that it is an unattainable end of the spectrum from completely predictable to completely unpredictable. But Randomness, meaning the degree to which something can be predicted, is very meaningful to us. To the point where we all change algorithms every year or two to keep the things we want to be not easily predicted to be relative to the current state of prediction. The observation that mt_rand() produces less predictable values than rand() is therefore useful.
Re: Here is a reason why not to use rand().
Posted: Wed Dec 31, 2008 10:57 am
by Eran
In real life, random is just a very long sequences of predetermined actions and phenomenoms. In computers, they are much much shorter.
Nothing is truly random. Nothing.
There are definitely completely random phenomenons that follow no deterministic pattern. You should read about chaos theory and quantum mechanics (I'm a physics major by the way).
Re: Here is a reason why not to use rand().
Posted: Wed Dec 31, 2008 11:14 am
by kaisellgren
arborint wrote:Random may be jshpro2's pot of gold in that it is an unattainable end of the spectrum from completely predictable to completely unpredictable. But Randomness, meaning the degree to which something can be predicted, is very meaningful to us. To the point where we all change algorithms every year or two to keep the things we want to be not easily predicted to be relative to the current state of prediction. The observation that mt_rand() produces less predictable values than rand() is therefore useful.
Thanks for that. I could have never put words in English better than you.
@pytrin: It's pointless to discuss really. Neither of us can actually know. My opinion is that no such thing exists. I have never received any proofs or one hundred percent theories about random and I probably never will. So it makes sense for me to stay at that opinion. I respect your opinion, and it's fine if you think that it is so.
But let's stay at PHP randomity and stop discussing about the real life or we are going a bit offtopic in here.
Re: Here is a reason why not to use rand().
Posted: Wed Dec 31, 2008 1:22 pm
by josh
wikiP wrote:In mathematics, chaos theory describes the behaviour of certain dynamical systems – that is, systems whose states evolve with time – that may exhibit dynamics that are highly sensitive to initial conditions (popularly referred to as the butterfly effect). As a result of this sensitivity, which manifests itself as an exponential growth of perturbations in the initial conditions, the behavior of chaotic systems appears to be random. This happens even though these systems are deterministic, meaning that their future dynamics are fully defined by their initial conditions, with no random elements involved.
Also there's morphology and then there's listemes, for everyone who uses "you're" I see someone who uses "your" in the same context, it appears some highly respected individuals due in fact use randomness interchangeable with entropy, however I think we can all agrue changing the "head" ( see chomsky theory ) meaning of a word when it is inflected ( or a suffix is added ) just confuses people in general. Random doesn't exist, "randomness" is a human concept referring to how much a system resembles the "imaginary random state".
My intentions are not to start a debate about linguistics, math, philosophy or science, merely to point out that mt_rand is "better", but not "perfect" and certainly not _as better_ as we perceive it to be. Yes it produces less entropy, which is harder _today_ to detect patterns in.. but everytime someone said something couldn't be done ( detect patterns in something "random" ), some one else always comes along with a counter-example one day
Some ways to measure / see non-randomness in something apparently random:
http://en.wikipedia.org/wiki/Random_var ... _variables
In the mt_rand version, sure it would be harder to guess exact coordinate, which I guess in your usage of the term makes it more random, yes. ( which for the context of this thread makes it the function of choice to use, when speed is not of the essence )
Here's both rand ( blue ) and mt_rand ( red ) plotted ontop of eachother:
At the weighted center of each distribution I have placed a circle. You may only see 1 circle, that is because they almost exactly overlap. Irrefutable evidence of a pattern common to both source functions of both number generating functions.
Re: Here is a reason why not to use rand().
Posted: Wed Dec 31, 2008 2:20 pm
by Eran
@pytrin: It's pointless to discuss really. Neither of us can actually know. My opinion is that no such thing exists. I have never received any proofs or one hundred percent theories about random and I probably never will. So it makes sense for me to stay at that opinion. I respect your opinion, and it's fine if you think that it is so.
It's really not my opinion.
Much of modern technology (including computers - semi-conductors) relies on the principles of quantum mechanics. You could claim that
you don't believe in it, but science is not based on belief but on (easily) reproduceable results. The fact is that on the quantum scale, sub-atomic particles don't have a determined location but rather a spread of possible probabilities (called a wave function) which an outside observer collapses into a physical location just by observing. That location is
random as far as modern science can stipulate - ie, it can never be determined beforehand where a specific particle will be in any particular observation. There is no pattern, only statistical probability.
Many have tried to refute this non-deterministic behavior over history (including Einstein, who said "
God doesn't play dice"), but so far it has stood the test of time and converted all previously non-believers. Until it is refuted (which seems less likely as time goes by and more and more sciences are developed around it), I will continue to regard its implications as fact.
Re: Here is a reason why not to use rand().
Posted: Wed Dec 31, 2008 2:26 pm
by kaisellgren
pytrin wrote:@pytrin: It's pointless to discuss really. Neither of us can actually know. My opinion is that no such thing exists. I have never received any proofs or one hundred percent theories about random and I probably never will. So it makes sense for me to stay at that opinion. I respect your opinion, and it's fine if you think that it is so.
It's really not my opinion.
Much of modern technology (including computers - semi-conductors) relies on the principles of quantum mechanics. You could claim that
you don't believe in it, but science is not based on belief but on (easily) reproduceable results. The fact is that on the quantum scale, sub-atomic particles don't have a determined location but rather a spread of possible probabilities (called a wave function) which an outside observer collapses into a physical location just by observing. That location is
random as far as modern science can stipulate - ie, it can never be determined beforehand where a specific particle will be in any particular observation. There is no pattern, only statistical probability.
Science is truth until elseway proven. So far almost everything is proven to be wrong later.
And by the way, the random you specified - it's not random. That's not the real definition of random. That may be an ultimately random-like to human beings.
Re: Here is a reason why not to use rand().
Posted: Wed Dec 31, 2008 2:33 pm
by Eran
Science is truth until elseway proven. So far almost everything is proven to be wrong later.
Don't know how you reached that conclusion. Much of science has been going through degrees of accuracy, but good science (ie, theories backed by physical evidence) is generally not wrong. Newtonian mechanics was not "wrong", it was inaccurate in speeds approaching the speed of light, so it needed an adjustment - the special theory of relativity. They both converged to the same results in slower speeds. Then quantum mechanics explained previously unknown phenomenon, and provide the basis for many other branches of physics such as thermodynamics. The theory itself might not be 100% correct, but its observable phenomona (such as random location for subatomic particles) is empirical fact that can not be brushed away by saying you don't believe in it.
EDIT:
As far as I know the definition of random is
"A random process is a repeating process whose outcomes follow no describable deterministic pattern, but follow a probability distribution"
(from
Wikipedia). That describes precisely how a quantum wave function describes the location/momentum correlation of a subatomic particle.