Random float number between 0 and 1.0 php

floating-point, integer, php, random

Solution

mt_rand() / mt_getrandmax();

Avoid the `rand()` function, since it usually depends on the platform's C `rand()` implementation, generally creating numbers with a very simple pattern. See this comment on php.net

Update: In php 7.1 the `rand()`has been changed and is now merely an alias of `mt_rand()`. Therefore it is now ok to use `rand()`, too.

Problem

Possible Duplicate: Random Float in php Is it possible to create a random float number between 0 and 1.0 e.g 0.4, 0.8 etc. I used rand but it only accepts integers.

Original source

Related problems