News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint.com:
How to Create Your Own Random Number Generator in PHP
February 09, 2012 @ 10:03:35

On SitePoint.com today there's a new tutorial showing how to create a random number generator in PHP (with the help of methods like mt_rand and mt_srand).

Computers cannot generate random numbers. A machine which works in ones and zeros is unable to magically invent its own stream of random data. However, computers can implement mathematical algorithms which produce pseudo-random numbers. They look like random numbers. They feel like random distributions. But they're fake; the same sequence of digits is generated if you run the algorithm twice.

Included in the post is code showing how to use the random functions and how to create a class (Random) that provides a few methods to help make generation easier - "seed" and "num". It first calls "seed" with a number to start the random generator off with and then "num" in a loop to pull out random values based on that.

0 comments voice your opinion now!
random number generator tutorial introduction mtrand


blog comments powered by Disqus

Similar Posts

Giorgio Sironi's Blog: PHPUnit and Phing cohabitation

PHP-Coding-Practices.com: Composing Methods: Split Temporary Variable

PHPMaster.com: PHP Namespaces

Pierre-Alain Joye's Blog: ext/filter, API frozen (!) and fixes, 0.11.0 is out

Matthew Weir O'Phinney's Blog: Cgiapp2 Tutorial 1 - Switch Template Plugins at Will


Community Events





Don't see your event here?
Let us know!


package language series release opinion podcast framework deployment voicesoftheelephpant introduction community symfony bugfix api laravel interview install zendserver unittest library

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework