PHP Generate List of Random Float Numbers Example

03-Apr-2023

.

Admin

PHP Generate List of Random Float Numbers Example

Hi Developer,

In this tutorial, we will see how to get the random float number using the rand() function in PHP, along with knowing its implementation through the example. The rand() is an inbuilt function in PHP used to generate a random float number.

The rand() function is used to generate a random float number. To generate a random float in some range.

In this example, we will use the rand() function. Create a function to generate a random float number. It will generate different float numbers between the 1 and 10 range.

Example:


<?php

//Get random float numbers

$randomFloat = rand(1, 10) / 10;

//print random float numbers

print_r($randomFloat);

?>

Output:

0.6

I hope it can help you...

#PHP