Re: Generating Random Numbers with Normal Distribution
| From: | Daniel Brown | Date: | Mon, 10 Dec 2007 22:15:28 +0000 |
| Subject: | Re: Generating Random Numbers with Normal Distribution | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265629@lists.php.net to get a copy of this message | ||
On Dec 10, 2007 2:28 PM, AmirBehzad Eslami <behzad.eslami@gmail.com> wrote:
> Dear list,
>
> For some computer-based simulation, i need to
> generate random numbers that have a normal distribution.
>
> It seems that PHP's rand() and mt_rand() functions return
> uniformly distributed numbers which is not suitable for
> simulation purposes.
Just for fun, I decided to write out an algorithm to randomize
with a never-known seed that would update constantly, with no human or
external script intervention required to initiate or maintain it.
What I came up with to count all CPU processing percentages of all
PIDs on the system, concatenate them into a single, long string, and
then add each number, in turn, to a running total; each number, in
succession, is added the sum of all numbers before it, until the end
of the number string has been reached.
Then the function runs through some other routines to see if
certain conditions are matched, and eventually returns the randomized
number.
Keep in mind that this is just something I put together in about
20 minutes, so it's far from perfect, but feel free to check it out.
http://www.pilotpig.net/code-library/source.php?f=rand.php
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.