WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A function that generates random numbers between 0 and 1 with precision that you set
Categories : PHP, Math.
Boaz Yahav
Date : May 03rd 2003
Grade : 4 of 5 (graded 7 times)
Viewed : 7081
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Boaz Yahav
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?
function GetSmallRandomNumber($precision) {
$r = rand(0,pow(10,$precision))/pow(10,$precision);
return $r;
}
?>


Example 1
=========
<?
GetSmallRandomNumber(0);
?>

will return 0 or 1

Example 2
=========
<?
GetSmallRandomNumber(1);
?>

will return numbers like 0.3 or 0.8 etc...

Example 3
=========
<?
GetSmallRandomNumber(4);
?>

will return numbers like 0.4507 or 0.8501 etc...



3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations.
Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs
Library of math functions to expand the functionality of PHP3. Version 1.2.1 fixes a major problem with the gcd function.
Categories : Algorithms, PHP, Math.
Diffusion-Limited Aggregation visualization
Categories : PHP, Graphics, Algorithms, Math.
Prime number finder (Sieve of Erastothenes)
Categories : PHP, Algorithms, Math.
Math operations on big numbers
Categories : PHP, Math.
Reverse a given number
Categories : PHP, Beginner Guides, Algorithms, Math.
Latitude-Longitude to Miles
Categories : PHP, Utilities, Math.
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other?
Categories : PHP, Math., Arrays
Temperature Conversion
Categories : PHP, Math., Beginner Guides
Easy to use random number function that seeds with uniqid and allows a max value
Categories : Math., PHP
decoct -- Decimal to octal
Categories : PHP, PHP Functions, Math.
Arbitrary Precision Math using BCMATH routines
Categories : PHP, Math., BC math
Show the steps for converting a number from a given base to base 10. Shows the steps involved in converting a number from a given base to base 10.
Categories : PHP, Math., Algorithms
How to judge if an integer is odd or is even in Php3?
Categories : Math., PHP, Algorithms
 P C wrote : 1093
I give this example a good grade for the following reasons:

1. The code does exactly what it says in the title, so it won`t waste your time if you`re not interested.

2. It is simple and accurate coding.  The purists among us may criticize that the repetition of the power function may be avoided.

3. It is complete with examples.

For those who tend to think that the code is trivial, please remember that the purpose of the code examples library caters for everyone, beginners to gurus alike.  Perhaps the forum could insert an attribute related to the level of difficulty to codes submitted.  This way, everyone will benefit more from the code examples.
 
 Chao Xu wrote :1680
You can just use lcg_value() and then take out the ending numbers you don`t need.
It does not work on large precision, like 1000th decimal. a BCMath version could be better(I`m making it :))