Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,868 questions

51,791 answers

573 users

How to generate a random float numbers between 0 (0.0...) to 1 (0.9...) in PHP

2 Answers

0 votes
for ($i = 0; $i < 30; $i++) {
      echo (float)rand() / (float)getrandmax() . "<br />"; 
}

 
 
   
/*
run:
        
0.74954692588632
0.13201814570093
0.91698365887487
0.042013413292362
0.6246805277768
0.97397961280028
0.082777827085358
0.80771824149774
0.59785135770117
0.4976555320889
0.63084494305348
0.68237553754932
0.74897585657843
0.99123260704392
0.44883407207617
0.67367195835042
0.37594135123116
0.87776778353274
0.32442348605228
0.020404045013899
0.85170671662861
0.59984983624883
0.25649896974512
0.74152220401052
0.12057481246096
0.81131554293042
0.50115890451761
0.11926282389055
0.34064717234142
0.45887394131109
 
*/

 



answered Jun 22, 2019 by avibootz
0 votes
for ($i = 0; $i < 40; $i++) {
      echo number_format((float)rand() / (float)getrandmax(), 2, ".", "") . "<br />"; 
}

 
 
   
/*
run:
        
0.12
0.39
0.31
0.95
0.89
0.68
0.01
0.97
0.35
0.21
0.22
0.47
0.14
0.86
0.01
0.59
0.30
0.04
0.39
0.08
0.76
0.18
0.54
0.07
0.34
0.17
0.95
0.11
0.87
0.22
0.90
0.80
0.34
0.36
0.94
0.01
0.49
0.18
0.38
0.21
 
*/

 



answered Jun 22, 2019 by avibootz

Related questions

1 answer 169 views
1 answer 314 views
1 answer 166 views
1 answer 171 views
1 answer 168 views
3 answers 313 views
...