Random numbers in PHP
3 posts
Page 1 of 1
This was originally ment to be in JavaScript, but I suggest looking at comathi's tutorial then
So there is one simple function in PHP to generate a random number. int rand(int $min, int $max). You do not have to specify the minimum and maximum value, they are optional, but useful if you need a number between a set range. The default min value is 0, and there is no default max, it varies from platform to platform. If you want to see the 'default' use the int getrandmax() function.
A sample PHP script could be:
So there is one simple function in PHP to generate a random number. int rand(int $min, int $max). You do not have to specify the minimum and maximum value, they are optional, but useful if you need a number between a set range. The default min value is 0, and there is no default max, it varies from platform to platform. If you want to see the 'default' use the int getrandmax() function.
A sample PHP script could be:
Code: Select all
For greater performance use the int mt_rand(int $min, int $max) function. It generates a better random value with better performance. To get the default max value use int mt_getrandmax instead of int getrandmax().<?php
echo "Default max value:\n"
echo getrandmax()
echo "\nRandom number between 10 and 50:\n"
echo rand(10, 50)
?>
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Haha no problem
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023